Intermediate · 20 XP
Flatten Deeply Nested Arrays
Write a function `flattenArray(arr)` that takes an array containing arbitrarily nested arrays and returns a single, completely flat 1-dimensional array. ### Requirements: - Do not use built-in `Array.prototype.flat(Infinity)`. - Handle empty arrays, single numbers, and arrays nested 5+ levels deep. - Preserve the original ordering of elements.
Show Step-by-Step Hint
- • You can use recursion by checking `Array.isArray(item)` for each element.
- • Alternatively, you can use a stack or `Array.prototype.reduce`.
Type: Code Challenge
Runtime: JAVASCRIPT
JAVASCRIPT solutionCHALLENGE #1