I have a list of appointments like the one below:
0: {start: '2022-02-23T09:30:00', end: '2022-02-23T10:00:00',…}
1: {start: '2022-02-23T10:00:00', end: '2022-02-23T10:30:00',…}
2: {start: '2022-02-23T10:30:00', end: '2022-02-23T11:00:00',…}
...
My goal is to find the first appointment that has free time in between its start
and end
For instance, if we examine the third appointment, it starts at 11:00 and ends at 11:30 with no gaps before. The next appointment starting at 12:00 creates a 30-minute gap from 11:30 to 12:00. I am looking to retrieve the end
property (or the entire appointment) of the first appointment without a direct follow-up.
Update: I have attempted the following code snippet
const latestAppointment = [...appointments].sort((a, b) => (new Date(a.end)) < (new Date(b.end)) ? -1 : 1)
I hope this explanation clarifies my question. Thank you.