Code for generating permutation in Javascript.