Build a Permutation Generator - Build a Permutation Generator

Tell us what’s happening:

i can see how my solution works but i just cant turn my idea into code. what is it that im missing? is this a skill issue?

step 1: take out the first letter in the remaining of the word. stop if the word’s length is 1: cat → c, at → a, t → t
step 2: insert the previous first letter into every position of the current first letter: a into t → at, ta
step 3: repeat the procedure until done: c into at and ta → cat, act, atc, cta, tca, tac

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:153.0) Gecko/20100101 Firefox/153.0

Challenge Information:

Build a Permutation Generator - Build a Permutation Generator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md at main · freeCodeCamp/freeCodeCamp · GitHub

are you trying to implement the algorithm explained in the description or trying to create your own?

What does it mean “insert prev first into every place of the newest one” in code?

yes! im trying to do what the description says.

what i meant was to insert the previous prefix in the recursion stack to the recent formed word starting with the last prefix (when the word’s length = 1). tbh, idk how to really describe it lol. i just see how it could work!

so what the description say is a bit different

like this would be the first step:

thanks! i can understand the diagram very clearly but i still cant turn whats in my head into code. not just this problem in particular but other hard ones as well. do u have any tips for me?

Maybe start with defining the function based on the information in the instructions. Then user stories 3 and 4 talk about iterating over the length of the string and what condition to use to push the prefix to the results array.

You might want to go back and review the code in the Decimal to Binary Converter workshop, which gives a nice visual of how recursion works when you enter the number 5.

you can try to build the whole diagram, it is not a bad idea

once you have the diagram for a specific case, then you can try to build the generic one for any case

and once you do that, then you can write the code