function normalizeInterval ( start , end ) { return { start : Math . min ( start , end ) , end : Math . max ( start , end ) } ; } export function intersect ( start1 , end1 , start2 , end2 ) { const { start : _start1 , end : _end1 } = normalizeInterval ( start1 , end1 ) ; const { start : _start2 , end : _end2 } = normalizeInterval ( start2 , end2 ) ; let shorter , longer ; if ( _end1 - _start1 > _end2 - _start2 ) { shorter = { start : _start2 , end : _end2 } ; longer = { start : _start1 , end : _end1 } ; } else { shorter = { start : _start1 , end : _end1 } ; longer = { start : _start2 , end : _end2 } ; } return ( between ( shorter . start , longer . start , longer . end ) || between ( shorter . end , longer . start , longer . end ) ) ; } function between ( num , bound1 , bound2 ) { return num >= bound1 && num <= bound2 ; } export default intersect ;