Sum function.

This commit is contained in:
Psychedelic Squid 2012-03-07 03:22:25 +00:00
parent f9538183fb
commit cfe2c0db4f

View File

@ -27,6 +27,14 @@ Array.prototype.include = function(value) {
return false;
};
Array.prototype.sum = function() {
var sum = 0;
for(var i=0;i<this.length;i++) {
sum += (parseFloat(this[i]) || 0);
}
return sum;
};
Array.prototype.allGroupings = function() {
if (this.length == 0) {
return []; /* short-circuit the empty-array case */