Created
June 26, 2017 21:16
-
-
Save rjbultitude/61dd3c64e65f30824d55c1bd5493cbb6 to your computer and use it in GitHub Desktop.
Largest negative number in 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 negative number in a given array | |
* @param {Array} arr [the array to act on] | |
* @return {Number} [the largest negative number] | |
*/ | |
function getLargestNegNumInArr(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