Extending js Array Prototype

Extending array prototype with sum, minimum, maximum and remove

http://snippets.dzone.com/posts/show/5753
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);
	}
}

你可能感兴趣的:(prototype)