A while ago a friend and I were looking at some JS functions and found out how crazy powerful Array.flat() is. For those that don't know, Array.flat() is a method that creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. Now you might be thinking "specified depth? What could that possibly be good for?" Well that's what I thought as well, until I realized how powerful it is. For example look at the beautiful function that computes Fibonacci numbers:
So simple and elegant! No crazy control flow patterns like recursion, not even a loop, just a single call to flat. I wonder what else this function can compute? I happen to be a physics student which means I have learned that if you wave your hands while saying "Taylor" every function turns into a Polynomial. So let's write a function that takes 3 positive integers a,b,c and returns the Array corresponding to ax^2+bx+c. In other words the function should be used like this:
Assume that a,b,c, and n are all non-zero positive integers.
Yo this submit button uses eval for obvious reasons, please don't copy-paste code you don't trust
Need a hint? Click below:
More hints? Click below:
Final hint? Click below: