Created
July 17, 2014 07:12
-
-
Save didymu5/13b0cf99c1a9165318e7 to your computer and use it in GitHub Desktop.
Summing an Array - Nice for totaling numerical value
This file contains 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
_.sum = function(obj) { | |
if (!$.isArray(obj) || obj.length == 0) { | |
return 0; | |
} | |
return _.reduce(obj, function(sum, n) { return sum += n; }); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment