Skip to content

Instantly share code, notes, and snippets.

@rjbultitude
Created June 26, 2017 21:15
Show Gist options
  • Save rjbultitude/2996a9b0de16f5e393547dd34b9c20f8 to your computer and use it in GitHub Desktop.
Save rjbultitude/2996a9b0de16f5e393547dd34b9c20f8 to your computer and use it in GitHub Desktop.
Get the largest number in an array
/**
* returns the largest positive number in a given array
* @param {Array} arr [the array to act on]
* @return {Array} [the largest number]
*/
function getLargestPosNumInArr(arr) {
return arr.reduce(function(prevVal, curVal) {
if (curVal > prevVal) {
prevVal = curVal;
}
return prevVal;
}, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment