My goal is to dynamically generate available appointment times based on the number of employees working at a given time and the number of slots already filled. Let's say we have two employees working, one from 4:30 - 7:00 and the other from 4:30 - 7:30, with each appointment lasting 30 minutes. This information is used to populate the possibleAppointments
array below.
const possibleAppointments = [
{ time: '4:30 PM' },
{ time: '4:30 PM' },
{ time: '5:00 PM' },
{ time: '5:00 PM' },
{ time: '5:30 PM' },
{ time: '5:30 PM' },
{ time: '6:00 PM' },
{ time: '6:00 PM' },
{ time: '6:30 PM' },
{ time: '6:30 PM' },
{ time: '7:00 PM' },
];
const reservedAppointments = [
{ time: '05:00 PM' }, // ends at 5:30
{ time: '6:10 PM' }, // ends at 6:40
{ time: '6:10 PM' }, // ends at 6:40
];
I am looking to utilize the possibleAppointments
and reservedAppointments
arrays above to construct an availableAppointments
array that excludes any conflicting time slots. The result should resemble the following array:
// availableAppointments
[
{ time: '4:30 PM' },
{ time: '4:30 PM' },
{ time: '5:00 PM' },
{ time: '5:30 PM' },
{ time: '5:30 PM' },
{ time: '7:00 PM' },
]
You can see one of my attempts using Stackblitz here: https://stackblitz.com/edit/angular-ivy-7h58ga?file=src/app/app.component.ts
I've been struggling with this for quite some time. How can I adjust the logic in the Stackblitz example to achieve the desired result where
availableAppointments === [
{ time: '4:30 PM' },
{ time: '4:30 PM' },
{ time: '5:00 PM' },
{ time: '5:30 PM' },
{ time: '5:30 PM' },
{ time: '7:00 PM' },
]