Steamroller: The results are correct but FCC isn't accepting my solution

Tell us what’s happening:

Your code so far


let newArr=[];
function steamrollArray(arr) {
if(arr.length>0){
arr.forEach(e=>{
  return (typeof(e) !== "object")?newArr.push(e) : steamrollArray(e) ;
})
}else if(!arr.length === 0){
newArr.push(arr);
}
return newArr;
}

console.log( steamrollArray([1, [], [3, [[4]]]]));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 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
1 Like