Skip to content

Instantly share code, notes, and snippets.

@brainyfarm
Created June 21, 2016 14:13
Show Gist options
  • Save brainyfarm/b9d6bd6fe2c2bfa659ae3ad187f8145e to your computer and use it in GitHub Desktop.
Save brainyfarm/b9d6bd6fe2c2bfa659ae3ad187f8145e to your computer and use it in GitHub Desktop.
Olawale/FreeCodeCamp Algorithm: Return Largest Number in an Array
function largestOfFour(arr){
return arr.map(function(subarr){
return Math.max.apply(null, subarr);
});
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
/**
Old solution below
function largestOfFour(arr){
// Create an empty array to store the largest item in each array
var bigBoys = [];
// Do Loop through each array.
for(var item in arr){
// Find the largest values in the array and push it into the bigBoys array
bigBoys.push(Math.max.apply(null, arr[item]));
}
// Return the array of large values
return bigBoys;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment