I have an object with the structure
"Office": {
"California" : {
"Contract1": {
1: {Price: 1000, Count: 5},
2: {Price: 2000, Count: 11},
3: {Price: 3000, Count: 3},
4: {Price: 2000, Count: 1},...
},
"Contract2": {
1: {Price: 7000, Count: 6},
2: {Price: 1000, Count: 4},
3: {Price: 67000, Count: 6},
4: {Price: 500, Count: 2},...
},
"Contract3": {
1: {Price: 4000, Count: 4},
2: {Price: 4000, Count: 1},
3: {Price: 5000, Count: 12},
4: {Price: 5000, Count: 2},...
}
},
"North Carolina" : {
"Contract1": {
1: {Price: 7000, Count: 4},
2: {Price: 7000, Count: 4},
3: {Price: 7000, Count: 4},
4: {Price: 7000, Count: 4},...
},
"Contract2": {
1: {Price: 6000, Count: 4},
2: {Price: 2000, Count: 10},
3: {Price: 3000, Count: 3},
4: {Price: 2000, Count: 3},...
},
"Contract3": {
1: {Price: 4000, Count: 5},
2: {Price: 2000, Count: 4},
3: {Price: 4000, Count: 3},
4: {Price: 2000, Count: 4},...
},...
}
And I want to reduce it to this:
"Office": {
"California" : {
"Contract1": {
1: {Price: 6000, Count: 19},
2: {Price: 2000, Count: 1},...
},
"Contract2": {
1: {Price: 75000, Count: 16},
2: {Price: 500, Count: 2},...
},
"Contract3": {
1: {Price: 13000, Count: 17},
2: {Price: 5000, Count: 2},...
}
},
"North Carolina" : {
"Contract1": {
1: {Price: 21000, Count: 12},
2: {Price: 7, Count: 4},...
},
"Contract2": {
1: {Price: 11000, Count: 17},
2: {Price: 2000, Count: 3},...
},
"Contract3": {
1: {Price: 10000, Count: 12},
2: {Price: 2000, Count: 4},...
},...
}
The number objects under each contract on the first structure represent the months past. In the second structure I want to sum up the properties of the first 3 number objects can call this 1. Then the second 3 would be 2. These are quarters.
I think I can do this with some sort of combination of map, reduce and filter but these are array functions and I have an object so I’m not sure how to do it. I need to do this for a non ES6 solution.
Any guidance would be really appreciated.
for...in...,for...of...,Object.keys(),Object.values(),Object.entries(),.map(),.reduce(), ...