Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
Last active January 2, 2016 16:38
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 nnarhinen/8331002 to your computer and use it in GitHub Desktop.
Save nnarhinen/8331002 to your computer and use it in GitHub Desktop.
function calculate (objects) {
return _.chain(objects)
.map(function(p) { return [p.vat, p.price]; })
.reduce(function(memo, pair) {
var o = {};
o[pair[0]] = (memo[pair[0]] || 0) + pair[1];
return _.extend({}, memo, o);
}, {}).value();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment