Basic Algorithm Scripting - Return Largest Numbers in Arrays

Tell us what’s happening:
Hey guy, I dont know why my code is wrong. Please show my wrong in this code.

Your code so far

function largestOfFour(arr) {
  let maxnum= 0;
  let newarr = [ ] ;

  for (let i=0; i< arr.length; i++) {
    for (let j=0; j< arr[i].length; j++) {
      if (arr[i][j]> maxnum) {
        maxnum =arr[i][j]; 
        newarr.push(maxnum);
      } 
    }

  }
  return newarr;
}

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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

What happens if the maximum in one subarray is smaller than in another?

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.