Permutation util for javascript