Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Last active May 3, 2016 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdavis512/78f05d5bd9d88d724b28b9d716881584 to your computer and use it in GitHub Desktop.
Save sethdavis512/78f05d5bd9d88d724b28b9d716881584 to your computer and use it in GitHub Desktop.
#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