All exercises

Deep flatten

CoreTypeScript

Runs entirely in your browser — your code never leaves your machine.

Problem

Flatten a nested array of numbers to any depth into a single flat array, left to right. flatten([1, [2, [3, [4]]]]) → [1, 2, 3, 4] Note: Array.prototype.flat(Infinity) would do it in one call — but implement it yourself (recursion or a stack) to practice the pattern.

Related cheat sheet
Your code
Press Run tests to check your solution.