Return-largest-numbers-in-arrays

Return-largest-numbers-in-arrays
0

#1

My code is working fine on jsbin but I don’t know why it is not working in freecodecamp…can anyone explaing why it is not working?

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

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

#2

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

#3

Thanks! Moving blank array inside the function worked!