Steamroller - Does not accept solution

Steamroller - Does not accept solution
0.0 0

#1

Tell us what’s happening:
Hello, I make a recursive function and when is running its doing right, but the evaluator report wrong in all. It would be a bug? Thank you!

Your code so far


var vect = [];
function recursion(arr)
{
  if(Array.isArray(arr)){
    for(var i=0;i<arr.length; i++)
      recursion(arr[i]);
  }
  else{
    vect.push(arr);
  }
}

function steamrollArray(arr) {
  recursion(arr);
  return vect;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:


#2

Move both the vect declaration and the recursion function inside steamrollArray function.


#3

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

#4

@randelldawson, thank you, It’s working,


#5

@ArielLeslie, that is something I didn’t know. Thank you for your response