Problem while testing

Tell us what’s happening:
I don’t know why the test failed even though i’ve tested them all and it was successful
Your code so far


let newArr=[];
function steamrollArray(arr) {
for(let i in arr){
  if(Array.isArray(arr[i])!=true){
    newArr.push(arr[i]);
  }
  else{
    steamrollArray(arr[i]);
  }
}
return newArr;
}

console.log(steamrollArray([1, {}, [3, [[4]]]]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Steamroller

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2

uh I get it thanks a lot

Now the hard part is rewriting your recursion to use the function return value rather than relying upon a global variable :slight_smile: