The title of this question probably isn't totally appropriate and requires much more explanation. The problem: compare a list (array #1) of all time-slots with a list (array #2) of booked time-slots and return a list of available time-slots.
The arrays:
{
"times": [
{
"start": "2017-05-11T19:00:00.000Z",
"stop": "2017-05-11T19:30:00.000Z"
},
{
"start": "2017-05-11T19:30:00.000Z",
"stop": "2017-05-11T20:00:00.000Z"
},
{
"start": "2017-05-11T20:00:00.000Z",
"stop": "2017-05-11T20:30:00.000Z"
},
{
"start": "2017-05-11T20:30:00.000Z",
"stop": "2017-05-11T21:00:00.000Z"
},
{
"start": "2017-05-11T21:00:00.000Z",
"stop": "2017-05-11T21:30:00.000Z"
},
{
"start": "2017-05-11T21:30:00.000Z",
"stop": "2017-05-11T22:00:00.000Z"
}
],
"booked": [
{
"start": "2017-05-11T19:00:00.000Z",
"stop": "2017-05-11T20:30:00.000Z"
}
]
}
The expected and desired result would be:
{
"start": "2017-05-11T20:30:00.000Z",
"stop": "2017-05-11T21:00:00.000Z"
},
{
"start": "2017-05-11T21:00:00.000Z",
"stop": "2017-05-11T21:30:00.000Z"
},
{
"start": "2017-05-11T21:30:00.000Z",
"stop": "2017-05-11T22:00:00.000Z"
}
I've solved similar problems in the past using map() or alasql but the difference is in the datetime comparison. Can someone point me in the right direction?
My current solution is in Node so I am looking for assistance using Node/JavaScript.
via David J Barnes
No comments:
Post a Comment