Skip to content

Instantly share code, notes, and snippets.

@nathggns
Created August 14, 2011 21:11
Show Gist options
  • Save nathggns/1145316 to your computer and use it in GitHub Desktop.
Save nathggns/1145316 to your computer and use it in GitHub Desktop.
Largest / Smallest value in an array
Array.prototype.max = function() {
var max = this[0];
var len = this.length;
for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
return max;
}
Array.prototype.min = function() {
var min = this[0];
var len = this.length;
for (var i = 1; i < len; i++) if (this[i] < min) min = this[i];
return min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment