Tell us what’s happening:
i tried solving this problem with recursion however i dont know if what i am doing is the correct way or if i am missing something it seems like i am close.
Your code so far
function steamrollArray(arr) {
let obj = []
let element
if(!Array.isArray(arr)){
element = arr
return element
}
else if(arr == '[object Object]'){
return JSON.stringify('{}')
}
else if(Array.isArray(arr) ){
arr.map(item=>{
obj.push(steamrollArray(item))
})
}
console.log(obj)
}
steamrollArray([1, {}, [3, [{},[4]]]]);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Steamroller
Link to the challenge: