JavaScript program to generate permutations with only one swap allowed .
function findPermutations ( str , index , n ) { if ( index >= n index + 1 >= n ) { document . write ( str . join ( " " ) + " " ) ; return ; }