I have an array of objects. Each object has a "tag" property with an array list. The values in this list repeat from object to object. I would like to sum up "cost" and "revenue" based on the "tag" arrays. Not sure explanation makes sense but I have the data structure below.
What I want the data to look like:
const expected =
[ { cost: 500, revenue: 800, tag: 'new' }
, { cost: 800, revenue: 1400, tag: 'equipment' }
, { cost: 1300, revenue: 1650, tag: 'wholesale' }
, { cost: 300, revenue: 600, tag: 'old' }
]
what the data looks like:
const data =
[ { cost: 500, revenue: 800, tag: [ 'new', 'equipment', 'wholesale' ]}
, { cost: 300, revenue: 600, tag: [ 'old', 'equipment' ]}
, { cost: 800, revenue: 850, tag: [ 'wholesale' ]}
]