UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

23 lines (22 loc) 780 B
const sortByDelay = (traj1, traj2) => { const props1 = traj1.properties; const props2 = traj2.properties; if (props1.delay === null && props2.delay !== null) { return 1; } if (props2.delay === null && props1.delay !== null) { return -1; } // We put cancelled train inbetween green and yellow trains // >=180000ms corresponds to yellow train // @ts-expect-error Verify that this property exists if (props1.cancelled && !props2.cancelled) { return props2.delay < 180000 ? -1 : 1; } // @ts-expect-error Verify that this property exists if (props2.cancelled && !props1.cancelled) { return props1.delay < 180000 ? 1 : -1; } return props2.delay - props1.delay; }; export default sortByDelay;