Largest number in an array of subarrays

Tell us what’s happening:
Describe your issue in detail here.
I have been having difficulty detecting my mistake in this code. I would appreciate any hint.

  **Your code so far**

function largestOfFour(arr) {
let newArr = [];
for(let i = 0; i < arr.length; ++i) {
  for(let a = 0; a < arr[i].length; ++a) {
    newArr[i] = arr[i][0];
    if(arr[i][a] > newArr[i]) newArr[i] = arr[i][a];
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/96.0.4664.110 Safari/537.36

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

This line:

newArr[i] = arr[i][0];

This line here… I get what you are trying to do, but is that the right place for it? I was able to move this line and get your code to pass. But don’t try random places to put it, understand why.


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