Created
June 21, 2016 14:13
-
-
Save brainyfarm/b9d6bd6fe2c2bfa659ae3ad187f8145e to your computer and use it in GitHub Desktop.
Olawale/FreeCodeCamp Algorithm: Return Largest Number in an Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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