Sorry I just realised, the question asks to return the array with the largest number. Anyway, i modified the code and now it returns the correct array in the console but still not passing the test.
the new code:
function largestOfFour(arr) {
// You can do this!
let greatest=0;
let greatArr=[];
for(let i=0; i<arr.length; i++){
for(let j=0; j<arr[i].length; j++){
if(arr[i][j]>greatest){
greatest=arr[i][j];
greatArr=arr[i];
}
}
}
return greatArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
That one just returns the largest numbers. It should return the largest number in EACH array. So if it’s 4 arrays, it should return one from each of those arrays, the largest ones.
Yours: [1000,1001,857,1] = All numbers in the last array.
Expected: [5, 27, 39, 1001] = Largest from Array 1, 2, 3, 4.
It is for this, largest is being set equal to i. so with the 4th subarray, i is 3, and 3 is bigger than all the numbers… it is for luck that everything else passes
Or better, it is being set equal to the first element of an array containing only i