The response from my http call is an array of company objects like this:
response = [{
"name": "CompanyName1",
"registrations": [
{
"country": "en",
"register": "registerType1",
"amount": 2
},
{
"country": "wa",
"register": "registerType2",
"amount": 1
},{
"country": "en",
"register": "registerType1",
"amount": 3
},
{
"country": "sc",
"register": "registerType3",
"amount": 2
},
{
"country": "wa",
"register": "registerType3",
"amount": 2
}
]
},
{
"name": "CompanyName2",
"registrations": [
{
"country": "wa",
"register": "registerType1",
"amount": 3
},
{
"country": "sc",
"register": "registerType3",
"amount": 1
}
]]
I need to group/sum company's registrations by register and country into a new propertyName (registerType_12) if registerType1 || registerType2 otherwise just keep property name registerTypeN. that is for companyName1 I need to get a result like this:
CompanyName1: [{country:en, registerType_12, amount:5},
{country:wa, registerTyoe_12, amount:1,
{country:sc, registerType3, amount:4}
}]