I need help removing booked time slots from the total time slots. How can I achieve this?
Input:
Actual time slots:
[ '10:00-10:30',
'10:30-11:00',
'11:00-11:30',
'11:30-12:00',
'12:00-12:30',
'12:30-13:00',
'13:00-13:30',
'13:30-14:00',
'14:00-14:30',
'14:30-15:00',
'15:00-15:30',
'15:30-16:00'
]
If Booked Time Slots are ["11:00-13:00", "14:00-15:00"]
, then the output should be:
[ '10:00-10:30',
'10:30-11:00',
'13:00-13:30',
'13:30-14:00',
'15:00-15:30',
'15:30-16:00'
]
If Booked Time Slots is ["11:15-13:15"]
, then the output should be:
[ '10:00-10:30',
'10:30-11:00',
'13:30-14:00',
'14:00-14:30',
'14:30-15:00',
'15:00-15:30',
'15:30-16:00'
]
I attempted to solve this problem with the following code:
let actualTimeSlot = []
for(let i = 0; i < times_ara.length; i++) {
if(parseInt(times_ara[i]) < parseInt(timeBooked.split("-")[0])){
actualTimeSlot.push(times_ara[i])
} else if(parseInt(times_ara[i]) > parseInt(timeBooked.split("-")[1])) {
actualTimeSlot.push(times_ara[i])
} else {
console.log("booked")
}
}
However, it's not working for all cases.