How can I group an array of objects after two properties? Is it possible to use reduce in the following case?
Ex: group the following array by country and city and sum the "age" property:
array = [
{
age: 20,
country: "England"
city: "London",
zip: "1234"
},
{
age: 25,
country: "England"
city: "London",
zip: "12345"
},
{
age: 40,
country: "England"
city: "Manchester",
zip: "123456"
}
]
/* expected result: */
expectedArray = [
{
age: 45, /* 20 + 25 */
country: "England"
city: "London",
zip: "Not relevant"
},
{
age: 40,
country: "England"
city: "Manchester",
zip: "NR"
]