3. implement Array.prototype.flat()

easy  - accepted / - tried

There is already Array.prototype.flat() in JavaScript (ES2019), which reduces the nesting of Array.

Could you manage to implement your own one?

Here is an example to illustrate

const arr = [1, [2], [3, [4]]];flat(arr)flat(arr, 1)flat(arr, 2)

follow up

Are you able to solve it both recursively and iteratively?

What is time & space complexity of your approach?