Permutation Game Hackerrank Javascript Coding