It merges an array of arrivals with departures and adds some values (1 when the train arrives and -1 when it departures). Result of it should be an array of sth like: [{time: 9:00, value: 1}, ....,{time: 2000, value: -1}]
Then I sort it like you did it.
.reduce is loop that's going through the "timetable" and it is doing two things:
add 1 if train comes and subtracts if it departures
check what is current number of trains and save max of this value
Hi ! thanks for your solution. Could you explain the flow of execution? I am not that well versed in javascript methods.
It merges an array of arrivals with departures and adds some values (1 when the train arrives and -1 when it departures). Result of it should be an array of sth like:
[{time: 9:00, value: 1}, ....,{time: 2000, value: -1}]
Then I sort it like you did it.
.reduce
is loop that's going through the "timetable" and it is doing two things:Wow! This is so efficient! Thanks for sharing it !!