Swap with the next character and revert the changes . As explained above , swapping with previous is is not needed as it anyways happens for next character .
swap ( str , index ) ; findPermutations ( str , index + 2 , n ) ; swap ( str , index ) ; } function swap ( arr , index ) { var temp = arr [ index ] ; arr [ index ] = arr [ index + 1 ] ; arr [ index + 1 ] = temp ; }