DevTrackSPEC
●3d
← Back to Coding Challenges
● CLIENT SANDBOX ISOLATED
◐MED
#arrays#recursion

Flatten Nested Array with Depth Control

Write a function `flatten(arr, depth)` that returns a new array with all sub-array elements concatenated recursively up to the specified `depth` (default is 1). Do not use `Array.prototype.flat`.
CONSTRAINTS

depth >= 0

TEST SPECIFICATIONS (2)
INPUT: [[1,[2,[3,4]]],1]
EXPECTED: [1,2,[3,4]]
INPUT: [[1,[2,[3,4]]],2]
EXPECTED: [1,2,3,4]
solution.js
INITIALIZING MONACO EDITOR...