Flatten Array
Difficulty: easy
Write flattenArray(arr), a function that takes a nested array and returns a new one-dimensional array.
Think of the array like boxes inside boxes. If an item is a normal value, put it into the answer. If an item is another array, open it and repeat the same process until no arrays are left.
Requirements
- Preserve the left-to-right order of values.
- Support any nesting depth.
- Return a new array. Do not mutate the input array.