I'm having some trouble with my array below I'd like to combine the objects that have the same timeslots.
I've tried looping through them and comparing all objects with eachothers timeslots. but (I think) because they are all seen as different instances it doesn't work.
I'm not asking for a full solution, but just some hints on how to compare these with eachother or how to approach this.
My array
[
{
"valid_days": ["0"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
}
]
},
{
"valid_days": ["1"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
}
]
},
{
"valid_days": ["2"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
},
{
"from_time": "13:00",
"to_time": "15:00"
}
]
},
{
"valid_days": ["3"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
},
{
"from_time": "13:00",
"to_time": "15:00"
}
]
}
]
Desired result
[
{
"valid_days": ["0", "1"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
}
]
},
{
"valid_days": ["2", "3"],
"timeslots": [
{
"from_time": "09:00",
"to_time": "12:00"
},
{
"from_time": "13:00",
"to_time": "15:00"
}
]
}
]