I have an array of objects representing products which I want to summarise the quantity value based on the value of multiple other properties. eg:
[
{
"title": "House Coffee",
"weight": "1kg",
"grind": "filter",
"quantity": 5
},
{
"title": "House Coffee",
"weight": "1kg",
"grind": "filter",
"quantity": 5
},
{
"title": "House Coffee",
"weight": "250g",
"grind": "Whole Beans",
"quantity": 4
},
{
"title": "House Coffee",
"weight": "250g",
"grind": "Whole Beans",
"quantity": 2
}
]
If all three properties of title
weight
and grind
are the same I want to reduce the quantity so that in this case I'd end up with a new array like:
[
{
"title": "House Coffee",
"weight": "1kg",
"grind": "filter",
"quantity": 10
},
{
"title": "House Coffee",
"weight": "250g",
"grind": "Whole Beans",
"quantity": 6
},
]