function largestOfFour(arr) {
// You can do this!
var arr2 = [];
var comp1 = 0;
for (i=0; i<arr.length; i++) {
for (j=0; j<arr[i].length; j++); {
if (arr[i][j] > comp1) {
comp1 = arr[i][j];
}
} arr2.push(comp1);
}
return arr2;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
My result is [5, 27, 39, 1001]. It says it should return [27,5,39,1001]. I don’t understand why I should be getting it in that weird order?? I’m so confused
I copied your code to repl.it and for the three tests, I always get [0, 0, 0, 0].
If you looked closely there’s a really subtle error with your syntax. Look at the inner loop’s header. After you find and fix that, I believe you only have to deal with some logic error with your code, and you’re done!
You just had to move var comp1 = 0; just before the inner loop starts. You only want to get the max number per subarray, so it makes sense to reset it before looping through a subarray.