JS Built-ins
TypeScriptadvanced

Advanced β€” flattenDeep

πŸ“– Usage Example
flattenDeep([1, [2, [3, [4]]]])   // β†’ [1, 2, 3, 4]

flattenDeep recursively flattens nested arrays to any depth into a single flat array.

Advanced: Recursive Flatten

Challenge: Implement flattenDeep(arr: unknown[]): unknown[] flattening arbitrarily nested arrays.

flattenDeep([1, [2, [3, [4]]]])  // β†’ [1, 2, 3, 4]
πŸ’‘ Hints (1)
  • β€’ Array.flat(Infinity) recursively flattens all levels.