Skip to content

Instantly share code, notes, and snippets.

@rjbultitude
Created June 26, 2017 21:16
Show Gist options
  • Save rjbultitude/61dd3c64e65f30824d55c1bd5493cbb6 to your computer and use it in GitHub Desktop.
Save rjbultitude/61dd3c64e65f30824d55c1bd5493cbb6 to your computer and use it in GitHub Desktop.
Largest negative number in array
/**
* 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