Tell us what’s happening:
I was wondering how to take the below code and merge it with the steamroller code, to allow steamroller to work when the arguments are multiple arrays.
//concatenate multiple arrays into 1
function uniteUnique(...arr) {
return [].concat(...arr)
}
uniteUnique([1, 3, 2], [5]);
//[1,3,2,5]
Your code so far
When I trying to add (…arr) as the parameter so I can flatten them all together it gives an error saying “range limit reached”. I’m guessing this has to do with the recursion hitting the … and mucking up. So how would I combine the two code?
i.e. I want to do something like
steamrollArray([1,2,3,4,[[3]]], [5], [8,[8]]);
//[1,2,3,4,3,5,8,8]
function steamrollArray(arr) {
let flat = [].concat(...arr)
return flat.some(Array.isArray)?steamrollArray(flat):flat
}
steamrollArray([1,2,3,4,[[3]]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Steamroller
Link to the challenge: