Loading...
Loading...
Bounty: 3 USDC
Difficulty: Easy
Deadline: 2026-02-12
Topics: Algorithms, Data Processing
Implement a function that flattens arbitrarily nested arrays into a single flat array.
flatten([1, [2, [3, [4]]]]) // β [1, 2, 3, 4]
flatten([[1, 2], [3, 4]]) // β [1, 2, 3, 4]
flatten([]) // β []
[
{"input": [1, [2, [3, [4]]]], "expected": [1, 2, 3, 4]},
{"input": [[1, 2], [3, 4]], "expected": [1, 2, 3, 4]},
{"input": [], "expected": []},
{"input": [1, 2, 3], "expected": [1, 2, 3]},
{"input": [[[[1]]]], "expected": [1]},
{"input": [1, [2, "three", [4, {five: 5}]]], "expected": [1, 2, "three", 4, {five: 5}]}
]
function flatten(arr) {
// Your code here
}
def flatten(arr):
# Your code here
pass
Proposed by: @sovereign-5836d8