Created
November 4, 2016 13:47
-
-
Save d30jeff/4732af965ac8db348ed77e467c5cf2b1 to your computer and use it in GitHub Desktop.
Min Max
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
/** | |
* Get the smallest integer in an array. | |
* @param {Array} arr Array of numbers. | |
* @return {Integer} The smallest integer. | |
*/ | |
function getMinimum(arr) { | |
var minValue = Infinity; | |
if (arr instanceof Array) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] !== null && arr[i] < minValue) | |
minValue = arr[i]; | |
} | |
return minValue; | |
} else { | |
throw Error('Expecting array, bullshit given.'); | |
} | |
} | |
/** | |
* Get the largest integer in an array. | |
* @param {Array} arr Array of numbers. | |
* @return {Integer} The largest integer. | |
*/ | |
function getMaximum(arr) { | |
var maxValue = -Infinity; | |
if (arr instanceof Array) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] !== null && arr[i] > maxValue) | |
maxValue = arr[i] | |
} | |
return maxValue; | |
} else { | |
throw Error('Expecting array, bullshit given.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment