Flatten a nested array
MediumRecursion · JavaScript
The task
Write flatten(arr) that returns a new flat array with all the values of arr, however deeply they are nested.
Do not use the built-in flat method; the point is to practise recursion.
Examples
- flatten([1, [2, [3, [4]]]]) returns [1,2,3,4]
Your code runs in your browser, in a separate worker, and is never sent to us. Edit the function, then press Run tests. Your work is saved here as you type.
JavaScriptCtrl or Cmd + Enter to run