Skip to content

Instantly share code, notes, and snippets.

@tan-yuki
Created April 26, 2014 06:39
Show Gist options
  • Save tan-yuki/11313358 to your computer and use it in GitHub Desktop.
Save tan-yuki/11313358 to your computer and use it in GitHub Desktop.
_.mixin({
sum: function(list, callback) {
return _.reduce(list, function(memo, item) {
return memo + callback(item);
}, 0);
}
});
// == test ==
// _.sum([{price:10}, {price:20}, {price:30}], function(item) { return item.price; });
// > 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment