Skip to content

Instantly share code, notes, and snippets.

@RuffSeason
Created July 7, 2016 17:06
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 RuffSeason/ebbd85652e828bc395d1967a50de6652 to your computer and use it in GitHub Desktop.
Save RuffSeason/ebbd85652e828bc395d1967a50de6652 to your computer and use it in GitHub Desktop.
Object Key Sum
var _n = require('underscore');
var async = require('async');
//sum all the keys in array of objects
function objectKeySum(object, properties) {
var response = {};
async.forEachOf(
properties,
function(value, key, callback) {
var summed = _n.reduce(_n.pluck(object,value), function (t,h) { return t+h }, 0);
response[value] = summed;
callback(response);
});
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment