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
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!
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.