I need to combine the objects whose prices are the same and add the quantity (amount
).
Example:
[
{price: 25.1, amount: 32},
{price: 45.2, amount: 45},
{price: 25.1, amount: 25},
{price: 44.0, amount: 13},
{price: 45.2, amount: 23}
]
Result:
[
{price: 25.1, amount: 57}, // 32 + 25
{price: 45.2, amount: 68}, // 45 + 23
{price: 44.0, amount: 13},
]