Prototype: Array#sum

February 19th, 2008

Array.prototype.sum || (Array.prototype.sum = function(iterator){
   var result = 0;
   this.each(function(value, index) {
      value = (iterator || Prototype.K)(value, index);
      try { result += parseInt(value || 0); } catch(e){}
   });
   return result;	
});

Sorry, comments are closed for this article.