Error in Steamroller Intermediate Algo Scripting Challenge?

My code passes fails all the automated tests, but when I manually check it seems like it should pass and actually does return the right value. Am I doing something wrong here?

var myArr = [];
function steamrollArray(arr) {
// for each element in the array
for(var i = 0; i < arr.length; i++){
// if that element is an array itself
if(Array.isArray(arr[i])){
// call the steamroller function on that element
steamrollArray(arr[i]);
} else {
// once you get to an element that is not an array, push that to element to the global myArr array.
myArr.push(arr[i]);
}
}

return myArr;
}

steamrollArray([1, [], [3, [[4]]]]);

//returns [1, 3, 4];

Not that this is your case, but I had an exercise keep failing although it gave me all the right answers (Roman Numeral one) And I went to put in a ticket and someone already had…

Resolution was to put all var declarations inside the function since it was testing against that function. something like that anyway… I did and it passed…

1 Like

@DarrenfJ

That worked! Had to change my code a bit, but putting everything within the scope of the steamRoller function did the trick.

1 Like