Iterate permutations of anagram

Tell us what’s happening:
Describe your issue in detail here.
I spent a good over an hour on this problem and don’t have any idea how to solve it. I kind of have an idea in my mind of how to iterate through all permutations of an anagram, but in practice it doesn’t work.

I’ve looked at many solutions online of iterating permuations of anagrams and none make any sense to me so can’t modify them for this.

any hints

  **Your code so far**

function permAlone(str) {
var num=0;
var cur;
for(var x=0; x<str.length; x++){
  for(var y=1; y<str.length; y++){
cur = str.replace(/./g, (c, i) => i == x+y? str.charAt(x): c)
cur = str.replace(/./g, (c, i) => i == x? str.charAt(x+y): c)

  if(cur.charAt(x+y)!=str.charAt(x+y-1)) num++;

return num;

  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: No Repeats Please

Link to the challenge:

I might be wrong, but wouldn’t it be better, if you found a way to calculate these numbers without actually creating the actual strings?
Also the challenge doesn’t include any anagrams.

1 Like

basically ignore the actual letters just know the possible number permutations without iterating through them

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.