You could extend the Array
type from Javascript, for sample:
Array.prototype.min = function(comparer) {
if (this.length === 0) return null;
if (this.length === 1) return this[0];
comparer = (comparer || Math.min);
var result = this[0];
for (var i = 1; i < this.length; i++)
result = comparer(this[i], v);
return result;
}
Array.prototype.max = function(comparer) {
if (this.length === 0) return null;
if (this.length === 1) return this[0];
comparer = (comparer || Math.max);
var result = this[0];
for (var i = 1; i < this.length; i++)
result = comparer(this[i], v);
return result;
}
And use something like this:
var minValue = yourArray.min();
var maxValue = yourArray.max();
Look the jsbin
: http://jsbin.com/yoyecono/1/edit