Steamroller Help me

Steamroller Help me
0.0 0

#1

Hey guys i need help to solve the Steamroller…here is my code.It’s suppose to flatten arrays which it does however it doesnt pass any test

Your code so far

function steamrollArray(arr) {
  // I'm a steamroller, baby
  
  for(var i =0,len = arr.length;i<len;i++){
    
    if(!Array.isArray(arr[i])){
        arrFlatten.push(arr[i]);
    }
    else{
      steamrollArray(arr[i]);
    }
  }
  return arrFlatten;
}

steamrollArray([1, [2], [3, [[4]]]]);



Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0.

Link to the challenge:


#2

If you check your console (Ctrl+Shft+I in chrome), then you would see an error message similar to the following:

ReferenceError: arrFlatten is not defined

You get this error when you try:

arrFlatten.push(arr[i]);

Since arrFlatten is not declared and initialized as an array, this error will display.