Tested code not passing. Why?

Tell us what’s happening:

Hey,

I would like to know why my code is not passing? I have tested it with console log and it is working normally.

Your code so far


var resultado = []
function largestOfFour(arr) {
for (var i = 0; i < arr.length; i++) {
  resultado.push(Math.max(...arr[i]))
}
return resultado;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36.

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

Because you declared empty array resultado outside of function. It should be inside the function.

Thanks, it worked. But before it was also working. The console log threw the array normally. The difference it was not only passing like an exercise done by FCC. :thinking:

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