13 lines
280 B
JavaScript
13 lines
280 B
JavaScript
const out = [];
|
|
function steamrollArray(arr) {
|
|
for (let item of arr) {
|
|
if (Array.isArray(item) === false) {
|
|
out.push(item);
|
|
} else if (Array.isArray(item)) {
|
|
steamrollArray(item);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
console.log(steamrollArray([1, [2], [3, [[4]]]]));
|