Steamroller challange

Steamroller challange
0

#1

This is the Steamroller challange problem solution. Every time answer is showing correct but FCC doesn’t take it. What is the reason?

**The Code is:

function steamrollArray(arr) {
  // I'm a steamroller, baby
  
  flattenArr(arr);
  console.log(newArr);
  return newArr;
}

function flattenArr(val) {
  for (var i = 0; i < val.length; i++) {
    if (!Array.isArray(val[i])) {
      newArr.push(val[i]);
    }
    else {
      flattenArr(val[i]);
    }
  }
}

var newArr = [];

steamrollArray([[["a"]], [["b"]]]);






* browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.110 Chrome/58.0.3029.110 Safari/537.36```.

**Link to the challenge:**
https://www.freecodecamp.org/challenges/steamroller

#2

You are using a global declaration for your newArr variable, which is causing your problem.

Move the var newArr = []; into your steamrollArray function. You will then need to pass it to your flattenArr function each time you call flattenArr, so you will need a second parameter for your flattenArr function.


#3

Thank you. It works :smiley:


#4

For an extra challenge, see if you can only use one function instead of the two.