Steamroller code not submitting

Steamroller code not submitting
0

#1

Tell us what’s happening:

Your code so far

function steamrollArray(arr) {
  // I'm a steamroller, baby
  
  for(var i=0;i<arguments[0].length;i++){
    if(!Array.isArray(arguments[0][i])){
      newarr.push(arguments[0][i]);
    }
    else{
      
    var req = steamrollArray(arguments[0][i]);
      newarr.concat(req);   
    }
  
  }
return newarr;
}
steamrollArray([1, {}, [3, [[4]]]]);

Your browser information:

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

Link to the challenge:


#2

For starters, you did not define newArr as something that should could push values into.

Look at your browser’s console (Ctrl+Shft+J in Chrome) to see the error you are receiving.


#3

@RandellDawson Plz have a look at
var newarr =[];
function steamrollArray(arr) {
// I’m a steamroller, baby

for(var i=0;i<arguments[0].length;i++){
if(!Array.isArray(arguments[0][i])){
newarr.push(arguments[0][i]);
}
else{

var req = steamrollArray(arguments[0][i]);
  newarr.concat(req);   
}

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

The Output is As expected in all cases it provides.


#4

That global variable newArr is going to cause you trouble with the FCC tests, because it will retain its last returned value from the function of the last test. Since you make a call using steamrollArray([1, {}, [3, [[4]]]]) in your code above, it newArr will start as [ 1, {}, 3, 4 ]. Then, when the FCC tests start with steamrollArray([[[“a”]], [[“b”]]]), newArr will already have [ 1, {}, 3, 4 ] and so the final return will be [ 1, {}, 3, 4, ‘a’, ‘b’ ]. This continues through the rest of the tests.


#5

Thanks I got that Thing :slight_smile: