Sobes.tech
Junior — Senior

Nested array flattening function without Array.flat()

livecode

Task condition

Create a function that flattens (unfolds) a nested array without using the Array.flat() method. Note that the nesting depth can reach up to 1000 levels.

Example call:

function flattenArray(arr) {
    // implementation
}

The function should accept one parameter — an array of any nesting depth, and return a new array containing all elements in a flat form.

Constraints:

  • It is forbidden to use the built-in Array.flat() and similar methods.
  • The maximum nesting depth can be up to 1000.
  • The solution must work correctly for arrays containing any data types, including other arrays, objects, numbers, strings, etc.