Batcher's odd-even mergesort algorithm for JavaScript. See docs. Parent is @aureooms/js-sort.
import { whole } from '@aureooms/js-odd-even-mergesort' ;
import { list } from '@aureooms/js-itertools' ;
import { increasing } from '@aureooms/js-compare' ;
import { swap } from '@aureooms/js-array' ;
let modules = list( whole( 4 ) ) ;
modules ; // [ [ 0 , 1 ] , [ 2 , 3 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 2 ] ]
let a = [ 3 , 1 , 2 , 4 ] ;
for ( let [ i , j ] of modules ) if ( increasing( a[i] , a[j] ) > 0 ) swap( a , i , j ) ;
// 3 ----1------1----------- 1
// | |
// 1 ----3------|-3----2---- 2
// | | |
// 2 ------2----2-|----3---- 3
// | |
// 4 ------4------4--------- 4
a ; // [ 1 , 2 , 3 , 4 ]