Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
Last active December 29, 2015 20:53
Show Gist options
  • Save jgarciaruiz/f3dcbd0759a9a22aace7 to your computer and use it in GitHub Desktop.
Save jgarciaruiz/f3dcbd0759a9a22aace7 to your computer and use it in GitHub Desktop.
Using apply function to find out the maximum/minimum value in an array
var numbers = [342, 16, 8, 345, 23, 436, 75];
highestVal(numbers);//436
lowestVal(numbers);//8
function highestVal(array){
var highestN = Math.max.apply(Math, array)
return highestN;
}
function lowestVal(array){
var lowestN = Math.min.apply(Math, array)
return lowestN;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment