Finding "spare time" in a day from within a list of events
- by MFB
I have a list of events which is always sorted chronologically. The start time is always followed by the end time. Times are strings formatted as 'HHmmss'.
// list of events
var events = [
'010000', // start
'013000', // end...
'053000',
'060000',
'161500',
'184500']
// desired output
var spares = [
'000000', // start
'010000', // end...
'013000',
'053000',
'060000',
'161500',
'184500',
'235959']
How can I programmatically create a new list of "spare time" from 000000 to 235959?
PS I'm trying to do this in Javascript, but any conceptual answer or pseudo code would be helpful too.