So I have the following structure:
[{
"isOpen": 1,
"weekday": 1,
"humanDay": "Monday",
"periods": [{
"openDay": "Monday",
"openTime": "12:00",
"closeDay": "Monday",
"closeTime": "14:30"
},
{
"openDay": "Monday",
"openTime": "19:00",
"closeDay": "Monday",
"closeTime": "22:30"
},
{
"openDay": "Monday",
"openTime": "23:00",
"closeDay": "Monday",
"closeTime": "23:30"
}
]
},
{
"isOpen": 1,
"weekday": 1,
"humanDay": "Tuesday",
"periods": [{
"openDay": "Tuesday",
"openTime": "12:00",
"closeDay": "Tuesday",
"closeTime": "14:30"
},
{
"openDay": "Tuesday",
"openTime": "19:00",
"closeDay": "Tuesday",
"closeTime": "22:30"
},
{
"openDay": "Tuesday",
"openTime": "23:00",
"closeDay": "Tuesday",
"closeTime": "23:30"
}
]
}
]
What I want to do, is if all periods for a given day are the same as any other day(matching by their openTime and closeTime) in the array to merge them (or just delete the second occurrence). If the periods are of a different length no action will occur. Also if just one of the openTime or closeTime is different, again no action will occur. So far I have tried looping through all days and comparing one with the following after it. Got stuck in comparing the periods. Tried following the explanation here - https://gomakethings.com/check-if-two-arrays-or-objects-are-equal-with-javascript/, but again got lost. The desired output will be:
[{
"isOpen": 1,
"weekday": 1,
"humanDay": "Monday, Tuesday",
"periods": [{
"openDay": "Monday",
"openTime": "12:00",
"closeDay": "Monday",
"closeTime": "14:30"
},
{
"openDay": "Monday",
"openTime": "19:00",
"closeDay": "Monday",
"closeTime": "22:30"
},
{
"openDay": "Monday",
"openTime": "23:00",
"closeDay": "Monday",
"closeTime": "23:30"
}
]
},
As I don't care about changing the openDay/closeDay in the periods. I want to do this check for all days in the array.