js permutation method is working