k7n4n5t3w4rt / dojo-vanillajs

0 stars 0 forks source link

Write a program to generate all potential anagrams of an input string #2

Open timofeysie opened 4 years ago

timofeysie commented 4 years ago

The kata

Using React with TypeScript,

Write a program to generate all potential anagrams of an input string.

For example, the potential anagrams of "biro" are

biro bior brio broi boir bori
ibro ibor irbo irob iobr iorb
rbio rboi ribo riob roib robi
obir obri oibr oirb orbi orib
timofeysie commented 4 years ago

I have created a new branch for this exercise, react-anagram.

The previous code would only create anagrams with two characters. The commit e7d1b0b1 contains some new functions which use recursion and a letter toggle function which will work for any length.

To do

Implement an anagram separator

The next issue is that the anagrams are printed with no spaces, and adding spaces to them will break all the tests.

Also the method for finding the anagrams in the tests should allow for some kind of anagram separation. Either a newline or separation character.

Add types and refactor solution

Another thing that needs to be refactored is using types for the functions. The current function re-uses the str variable as an array. Possibly another function needs to be added to split the input into an array before calling the findAllPermutations() function.

const findAllPermutations = (str, index?, buffer?) => {
  if (typeof str == "string") str = str.split("");