Javascript Array sum(begin, end)
Array.prototype.sum = function(begin, end) { var total = 0;// ww w .ja va 2 s. c o m for (var i = begin >> 0 || 0, len = end + 1 >> 0 || this.length >> 0; i < len; i++) { total += +this[i] || 0; } return total; };