Steamroller passes tests but...doesn't pass tests!

Tell us what’s happening:
I wrote some code for the Steamroller exercise in the Intermediate Algorithm Scripting unit. I have pasted in all of the test cases to log out the results and they all return the correct values, but the test results just says that they should return the correct values!
Any idea why this is not being accepted? Thanks!

Your code so far


function steamrollArray(arr) {
for(let x in arr){
  if(Array.isArray(arr[x])){
    steamrollArray(arr[x]);
  }else{
    newArr.push(arr[x]);
  }
}
return newArr;
}
var newArr = [];
console.log(steamrollArray([[["a"]], [["b"]]]));
var newArr = [];
console.log(steamrollArray([1, [2], [3, [[4]]]]));
var newArr = [];
console.log(steamrollArray([1, [], [3, [[4]]]]));
var newArr = [];
console.log(steamrollArray([1, {}, [3, [[4]]]]));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: Steamroller

Link to the challenge:

You are using a global variable. Your code should work fine if you instead put declaration of newArray inside of the function.

In general, its a best practice to avoid using global variables in functions.

Edit: Woops, the way you’ve coded this, removing the global variable will be a little bit tricky. It’s doable, but you will have to be a bit more careful about your recursion.