What is the best way to take the following array of objects and combine them by key and accumulate the price so that the this:
var sales = [
{
order_id: 138,
price: 25,
},
{
order_id: 138,
price: 30,
},
{
order_id: 139,
price: 15,
},
{
order_id: 131,
price: 25,
},
];
become this:
var sales = [
{
order_id: 138,
price: 55,
},
{
order_id: 139,
price: 15,
},
{
order_id: 131,
price: 25,
},
];
Note that the initial array will contain 500+ items. Is this a good usecase for reduce? or do I need to build a whole new array with a for loop?