Permutation Game Hackerrank Javascript Solutions