Created
August 2, 2011 22:20
-
-
Save jdlich/1121375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.sum = function() { | |
var sum = 0; | |
for ( var i = 0; i < this.length; i++ ) { | |
sum += this[i]; | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if it's supported in the browser you could use reduce. here is a link with tutorial and prototype in case the browser doens't have it.
http://www.tutorialspoint.com/javascript/array_reduce.htm
basically: