Last active
December 31, 2015 00:19
-
-
Save ybrdev/7906380 to your computer and use it in GitHub Desktop.
Function to find maximum and minimum value on JavaScript Array.
This file contains hidden or 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 maximum value from array | |
function findMax(array) { | |
var max = 0; | |
var a = array.length; | |
for (counter=0; counter<a; counter++) { | |
if (array[counter] > max) { | |
max = array[counter]; | |
} | |
} | |
return max; | |
} | |
// Get minimum value from array | |
function findMin(array) { | |
var min = array[0]; | |
var a = array.length; | |
for (counter=0; counter<a; counter++) { | |
if (array[counter] < min) { | |
min = array[counter]; | |
} | |
} | |
return min; | |
} | |
// http://stackoverflow.com/questions/1379553/how-might-i-find-the-largest-number-contained-in-a-javascript-array/20214662#20214662 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment