Skip to content

Instantly share code, notes, and snippets.

@didymu5
Created July 17, 2014 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didymu5/13b0cf99c1a9165318e7 to your computer and use it in GitHub Desktop.
Save didymu5/13b0cf99c1a9165318e7 to your computer and use it in GitHub Desktop.
Summing an Array - Nice for totaling numerical value
_.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