Standard Lomuto partition function
function partition ( arr , low , high ) { let temp ; let pivot = arr [ high ] ; let i = ( low - 1 ) ; for ( let j = low ; j <= high - 1 ; j ++ ) { if ( arr [ j ] <= pivot ) { i ++ ; temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } temp = arr [ i + 1 ] ; arr [ i + 1 ] = arr [ high ] ; arr [ high ] = temp ; return ( i + 1 ) ; }