Skip to content

Instantly share code, notes, and snippets.

@platypusrex
Created October 15, 2015 15:24
Show Gist options
  • Save platypusrex/2ae36fcfb38587794e4a to your computer and use it in GitHub Desktop.
Save platypusrex/2ae36fcfb38587794e4a to your computer and use it in GitHub Desktop.
Javascript - Return an array consisting of the largest number from each provided sub-array
function largest(arr) {
return arr.map(function(val){
return val.reduce(function(prev, current){
return current > prev ? current : prev;
});
});
}
console.log(largest([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment