I am trying to get it right and I am having problems, so I have to ask ppl with a lot of experience. I have an array of objects that let you call the elements to be called, and I need to bring some properties to the various objects in the array and sum them at the end. The user can make several choices, and I only need to summarize only the selected properties in the array that they gave me, so I thought maybe I could use the _.pick function in lodash. If possible, I would like to do this in a single loop, since an array of elements can have up to 1000 elements. Here is an example:
var items = [
{'lightBlue':4, 'darkBlue':2, 'red':4, 'orange':6, 'purple':7},
{'lightBlue':6, 'darkBlue':5, 'red':1, 'orange':2, 'purple':3},
{'lightBlue':2, 'darkBlue':4, 'red':3, 'orange':4, 'purple':9}
]
var userSelectedColors = ['lightBlue', 'darkBlue'];
What I want to see is all blue, like:
var summedUp = [{'lightBlue':12, 'darkBlue':11}];
Then summarize the results to get the total number no
var totalCount = 23
lodash. userSelectedColors 1 .
, !