Three ways you can find the largest number in an array using JavaScript
Sonya Moisset
1.4K26

i used a for loop to sort each subarray from largest to smallest, then pushed the first index to an empty array. Seems to work.

function largestOfFour(arr) {
 var numbers = [];
 for (var i = 0; i < arr.length; i++) {
 arr[i].sort(function(a, b) {
 return b — a;
 });
 numbers.push(arr[i][0]);
 }
 return numbers;
}

Like what you read? Give Anthony Blackman a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.