Completed functionality for permutations in JS.