Slide 33
Slide 33 text
for (let i in connections) {
const connection = connections[i];
// If we never arrived to this connection’s departure stop,
// we never will as connections are ordered by departure time
if (typeof arrivalTimes[connection.departure_stop] === 'undefined') {
continue;
}
// If the connection leaves before we arrive at its departure, it can't be used
if (arrivalTimes[connection.departure_stop] > connection.departure_time) {
continue;
}
// If there already was a connection but the previous connection arrived
// earlier, keep the previous one
if (arrivalTimes[connection.arrival_stop] < connection.arrival_time) {
continue;
}
// Otherwise, we know for sure this connection is better than what we had
arrivalTimes[connection.arrival_stop] = connection.arrival_time;
inConnection[connection.arrival_stop] = connection;
}
A to B
7:00 to 7:05
B to C
7:06 to 7:09
B to D
7:07 to 7:11
C to E
7:10 to 7:15
B to E
7:11 to 7:18
G to D
7:08 to 7:11
D to E
7:12 to 7:17