I have an array of objects, like so:
[
{
Daypart: "G_POSTPEAK",
day_of_week: "Monday",
uplift: 1
},
{
Daypart: "A_BREAKFAST",
day_of_week: "Thursday",
uplift: 1
},
{
Daypart: "C_DAYTIME",
day_of_week: "Sunday",
uplift: 2
},
{
Daypart: "G_POSTPEAK",
day_of_week: "Monday",
uplift: 2
},
]
I have only shown a sample of objects in the array, I am working with a lot more. They all have the specified properties, the daypart property could be one of 8 values and the day of week value could be one of 7 (days of the week).
I want to return the sum of the uplift value for all the objects that have the same daypart and day_of_week value.
So the above should return something like:
{
G_POSTPEAK_Monday: {
Daypart: "G_POSTPEAK",
day_of_week: "Monday",
uplift: 3
},
A_BREAKFAST_Thursday: {
Daypart: "A_BREAKFAST",
day_of_week: "Thursday",
uplift: 1
},
C_DAYTIME_Sunday: {
Daypart: "C_DAYTIME",
day_of_week: "Sunday",
uplift: 2
}
}
Appreciate any help