Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Last active May 3, 2016 20:19
Embed
What would you like to do?
#post Find Max/Min Value in Array

Found this gem from 2011. Credits: http://www.devcurry.com/2011/10/javascript-max-min-array.html

Array.prototype.max = function () {
    return Math.max.apply(Math, this);
};

Array.prototype.min = function () {
    return Math.min.apply(Math, this);
};

//All you have to do now is call these methods on an array:
var max = [10, 12, 18, 24, 15].max();
var min = [10, 12, 18, 24, 15].min();
alert("Max Number: " + max + " Min Number: " + min);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment