Skip to content

Commit 2938bac

Browse files
improve permutation generator description (freeCodeCamp#64723)
Co-authored-by: Dario <[email protected]>
1 parent e40e8b9 commit 2938bac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

curriculum/challenges/english/blocks/lab-permutation-generator/66fe4f33a2cc9b33f4d5cd9b.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ dashedName: build-a-permutation-generator
99

1010
In this lab, you will build a permutation generator that will take a string and return all possible permutations of the characters in the string. For example, the possible permutations of the string `cat` are `cat`, `cta`, `act`, `atc`, `tac`, and `tca`.
1111

12+
The recursive way of creating permutations of a string works by storing the fixed starting part of the string (prefix), and creating permutations of the rest.
13+
14+
For example, let's consider the word `machine`. The first round of creating permutations would be made fixing the `m` as the prefix of the string, and then creating permutations of the rest of the string, `achine`.
15+
16+
For the rest of the string, permutations continue in the same way. One letter is added to the prefix, maybe the `c`, so the prefix becomes `mc`. Then, each of the permutations of `ahine` is concatenated to the prefix.
17+
18+
This continues until the prefix has all the letters, and the rest of the string is empty, that means one permutation has been created.
19+
1220
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
1321

1422
**User Stories:**
1523

1624
1. You should create a function named `permuteString`.
17-
2. The `permuteString` function should take three parameters- a string, a prefix value and an empty array for storing and returning the results. The prefix value would accumulate characters to form a permutation.
25+
2. The `permuteString` function should take three parameters: a string, a prefix value and an empty array for storing and returning the results. The prefix value should be a string used to accumulate characters to form a permutation.
1826
3. Inside the function, you should check if the length of the passed string is `0`. If it is, push the current prefix to the results and return the results.
1927
4. Iterate over each character in the input string and for each iteration, remove the current character from the string and call the `permuteString` function recursively with updated arguments to build the remaining permutations.
2028
5. You should return the final results array.

0 commit comments

Comments
 (0)