Next Permutation Problem In Leetcode Javascript