Tell us what’s happening:
So I can get as far as flattening most of the array down, however I don’t understand why my reduce function stops before completely flattening the array. because as it goes across the array, before it finds the integer 4. Array.isArray should return true and therefore continue to concat the array no?
Your code so far
function steamrollArray(arr) {
console.log(arr.reduce((acc, item) => {
if (Array.isArray(item)){
return acc.concat(item);
} else {
return [item];
}
},[])
)
}
steamrollArray([1, [2], [3, [[4]]]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Steamroller
Link to the challenge: