Return Largest Numbers in Array

Return Largest Numbers in Array


My code works for one of the tests but it fails for the second one but I unfortunately cannot figure out why. Any help is greatly appreciated. Thank you.

function largestOfFour(arr) {
  var  largestNumber=0;
  var bigNum=[];
 for(var i=0; i<arr.length; i++){
     var subArray =arr[i];
     for(var j=0; j<subArray.length;j++ ){
     return bigNum;

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


Can’t remember the challenge rules but you are not resetting largestNumber after the second loop completes.

The second array’s highest number will show as 27 instead of 5.


How in my code do I make sure that it resets each time?


ye on first array[0] 27 is highest but you then are checking arry[1] to see if they are higher than 27.
you need to reset largestNumber each time you check a array … so just set largestNumber back to 0 after you push to bigNum


Ahhhh so simple yet so confusing. Thank you very much!