algorithms/steamroller.js
2024-01-12 07:01:06 -05:00

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]]]]));