Steamroller (tests not working)

Steamroller (tests not working)
0.0 0

#1

Tell us what’s happening:

So, this code solves all the problems, but it’s not passing the test and I don’t know why. Anybody have any ideas? Thank you for your help.

Your code so far

var good=[];
function steamrollArray(arr) {
  for(var i = 0; i<arr.length; i++){
    if(Array.isArray(arr[i])){
      var newArr = steamrollArray(arr[i]);
    }else{
      good.push(arr[i]);
    }  
  }
  return good ;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2

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 new 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