param { number [ ] } array return { number [ ] } function BubbleSort ( array ) { for ( let i = 0 ; i < array . length ; i ++ ) { for ( let j = 0 ; j < array . length - i - 1 ; j ++ ) { if ( array [ j ] > array [ j + 1 ] ) { [ array [ j ] , array [ j + 1 ] ] = [ array [ j + 1 ] , array [ j ] ] ; } } } return array ; } param { number [ ] } array return { number [ ] } function BubbleSortBetter ( array ) { let i = array . length - 1 ; while ( i > 0 ) { let position = 0 ; for ( let j = 0 ; j < i ; j ++ ) { if ( array [ j ] > array [ j + 1 ] ) { position = j ; [ array [ j ] , array [ j + 1 ] ] = [ array [ j + 1 ] , array [ j ] ] ; } } i = position ; } return array ; } export { BubbleSort , BubbleSortBetter } ;