param { number [ ] [ ] } intervals return { number [ ] [ ] } function merge ( intervals ) { let result = [ ] ; let len = intervals . length ; if ( len === 0 ) { return [ ] ; } intervals . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ; let i = 0 ; while ( i < len ) { let currentLeft = intervals [ i ] [ 0 ] ; let currentRight = intervals [ i ] [ 1 ] ; while ( i < len - 1 && intervals [ i + 1 ] [ 0 ] <= currentRight ) { i ++ ; currentRight = Math . max ( currentRight , intervals [ i ] [ 1 ] ) ; } result . push ( [ currentLeft , currentRight ] ) ; i ++ ; } return result ; } export { merge } ;