Tell us what’s happening:
i am trying to solve this challenge, i approached this problem with a recursion and when i console log the result seems fine but freecodecamp is not accepting it.
Your code so far
function steamrollArray(arr) {
let result = []
let index = [];
let obj = []
if(!Array.isArray(arr)){
result.push(arr)
}
else {
arr.map(item=>{
if(item == '[object Object]'){
index.push(JSON.stringify(item))
}
else{
index.push(steamrollArray(item))
}
})
}
result+=index
obj = result
console.log(obj)
return 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.
Not really. Your solution needs a bit of work.
Start with an empty array.
Filter the given array and push the values you want to keep into the newly created one.
Try that if you like.
I think most solutions never create it as a string in the first place. For most solutions, they just have an array and push on the elements as they’re found.