Created
July 7, 2016 17:06
-
-
Save RuffSeason/ebbd85652e828bc395d1967a50de6652 to your computer and use it in GitHub Desktop.
Object Key Sum
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
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