param { number [ ] } array return { number [ ] } function MergeSort ( array ) { if ( array . length < 2 ) { return array ; } const mid = Math . floor ( array . length / 2 ) ; let front = array . slice ( 0 , mid ) ; let end = array . slice ( mid ) ; return merge ( MergeSort ( front ) , MergeSort ( end ) ) ; } param { number [ ] } front param { number [ ] } end function merge ( front , end ) { const temp = [ ] ; while ( front . length && end . length ) { if ( front [ 0 ] < end [ 0 ] ) { temp . push ( front . shift ( ) ) ; } else { temp . push ( end . shift ( ) ) ; } } while ( front . length ) { temp . push ( front . shift ( ) ) ; } while ( end . length ) { temp . push ( end . shift ( ) ) ; } return temp ; } export default MergeSort ;