How do I reduce this object array and and map it to a new array?
My data:
var objArray =
[{
state: 'NY',
type: 'A',
population: 100
},
{
state: 'NY',
type: 'A',
population: 300
},
{
state: 'NY',
type: 'B',
population: 200
},
{
state: 'CA',
type: 'A',
population: 400
},
{
state: 'CA',
type: 'A',
population: 400
}];
If an entry has the same state
AND type
I need to combine it into a single entry and sum their populations.
Finally I need to map it to an array in this format.
var outputArray = [ ['A', 'NY', 400 ], ['B', 'NY', 200], ['A', 'CA', 800] ]