Hello I wanted to use recursion for the Steam roller question in Intermediate Algorithm Scripting section.
I created a global array variable named result and created it above the function (so it would be global).
My code works perfectly in jsfiddle.net and on vs Code but freecodecamp is not accepting even one of the provided test cases.
Please not that all the test cases are passing in jsfiddle.net and are returning the array as mentioned on FCC.
Here is the code:
var result = [];
function steamrollArray(arr) {
// I'm a steamroller, baby
var temp;
for (var i = 0; i < arr.length; i++) {
if (!Array.isArray(arr[i]))
result.push(arr[i]);
else
steamrollArray(arr[i]);
}
console.log(result);
return result;
}
steamrollArray([1, {}, [3, [[4]]]]);