Tell us what’s happening:
The JSON.stringify before (and also after calling the function) returning the answer prints the correct answer. I can’t figure out what’s wrong.
Your code so far
let ans = [];
function steamrollArray(arr) {
for (let i in arr) {
if (typeof arr[i] == "object") {
console.log("steamrolling ", JSON.stringify(arr[i]));
steamrollArray(arr[i]);
} else {
console.log("pushing", arr[i]);
ans.push(arr[i]);
}
}
console.log(JSON.stringify(ans));
return ans;
}
steamrollArray([1, [1], [3, [[4]],],]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller