Return largest numbers in Arrays tell my why

Tell us what’s happening:
Why it worked 2 out of 4 tests. Tell me where I’m wrong .
Thanks for answering me

Your code so far


function largestOfFour(arr) {
var largestNum=-Infinity;
var resultArr=[];
arr.map(subArr=>{
  for(var i=0; i<subArr.length; i++){
    if(subArr[i]>largestNum){
      largestNum=subArr[i];
    }
  }
  resultArr.push(largestNum);
})
return (resultArr)
}

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 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36.

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

You have two related things here.

  1. I wouldn’t use -Infinity. There is a better choice of inital value for each subarray

  2. You never reset largestNum in between subarrays

1 Like

I solved this test.
Thanks a lot