Need help return largest number in array challenge


#1

hello people.
Any idea why this code is returning for return largest number in array challenge

  [27,0,39,1001]

instead of

[27,5,39,1001]
function largestOfFour(arr) {
   var numberaccessed=0;
  var bigarray=[];
  var numberaccessedarr;
  for(i=0;i<arr.length;i++){ 
    numberaccessedarr=0;
    for(j=0;j<arr[i].length;j++){

      if(numberaccessed<arr[i][j]){
        numberaccessed=arr[i][j];
        numberaccessedarr=numberaccessed;
      }

    }

    bigarray=bigarray.concat(numberaccessedarr);
  }
  return bigarray;
}
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

for the algorithm challenge return largest number in array
EDIT: Got solved at gitter
had to reinitialise numberaccessed too…


#2

Maybe look into sort(). Will do most of your heavy lifting.


#3

Hello there.
on the second line just define variable, don’t set it to 0.var numberaccessed;
set it to zero on 6th line numberaccessedarr=0;numberaccessed=0;