I'm a beginning coder who has been learning through FCC. I'm currently trying to solve an algorithm challenge in which I must return an array consisting of the largest number from each subarray. Explanations of what I'm missing or doing incorrectly are greatly appreciate, as it is currently only returning the zero index of the first array.
my code so far:
function largestOfFour(arr) {
var i = 0;
for (i = 0; i < arr.length; i++){
arr[i].sort(function(a, b){return b-a});
return arr[i][0];
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);