Sort the intervals based on velocity
test . sort ( function ( a , b ) { return ( a . v < b . v ? 1 : 0 ) ; } ) ; for ( let i = 0 ; i < N ; i ++ ) { let count = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) count [ i ] = 0 ; let current_velocity = test [ i ] . v ; let j = i ;