Product List
[{ id: 1, title: 'shirt', price: 2000 },
{ id: 2, title: 'shirt', price: 4000},
{ id: 3, title: 'tshirt', price: 10000}]
Desired Result
[{ id: 1, title: 'shirt', price: 6000 }, // 2000 + 4000
{ id: 3, title: 'tshirt', price: 10000}]
Attempted Various Methods with no Success.
I have been able to retrieve distinct products but require the sum of prices as well.
let result = products.filter((product, index, self) =>
index === self.findIndex((t) => (t.title === product.title))
)
console.log(result);