This function swaps d elements starting at index fi with d elements starting at index si
let swap = ( arr , fi , si , d ) => { for ( let i = 0 ; i < d ; i ++ ) { let temp = arr [ fi + i ] ; arr [ fi + i ] = arr [ si + i ] ; arr [ si + i ] = temp ; } return arr }