Created
June 26, 2017 21:15
-
-
Save rjbultitude/2996a9b0de16f5e393547dd34b9c20f8 to your computer and use it in GitHub Desktop.
Get the largest number in an array
This file contains 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
/** | |
* 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