[size=large][b]Extending array prototype with sum, minimum, maximum and remove[/b][/size]
[url]http://snippets.dzone.com/posts/show/5753[/url]
[url]http://snippets.dzone.com/posts/show/5753[/url]
Array.prototype.sum = function(){
for (var i=0, sum=0; i < this.length; sum += this[i++]);
return sum;
}
Array.prototype.max = function(){
return Math.max.apply({},this)
}
Array.prototype.min = function(){
return Math.min.apply({},this)
}
Array.prototype.remove=function(s){
for (i=0; i < this.length; i++){
if (s == this[i]) this.splice(i, 1);
}
}