pop and swap
let pop = stack . pop ( ) ; let index = pop [ 0 ] , val = pop [ 1 ] ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( [ i , arr [ i ] ] ) ; } else stack . push ( [ i , arr [ i ] ] ) ; }