Let's say I've got these two arrays:
const initial: Array<GivenObj> = [
{name: 'a', times: 40, other: 50},
{name: 'b', times: 10, other: 15},
{name: 'c', times: 15, other: 12}
];
const toBeMerged: Array<GivenObj> = [
{name: 'a', times: 45, other: 30},
{name: 'c', times: 10, other: 10},
{name: 'd', times: 23, other: 10}
];
These two arrays contain different values, but similar keys. I need to aggregate this data to a single array that will contain both of their values, but uniquely.
In code, the two arrays above should be aggregated as follows:
const aggregated: Array<GivenObj> = [
{name: 'a', times: 85, other: 80},
{name: 'b', times: 10, other: 15},
{name: 'c', times: 25, other: 22},
{name: 'd', times: 23, other: 10}
];
I was wondering what's the best way to aggregate data between two arrays.