Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Created February 23, 2021 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/78e3e9217799be0eefd2ee6f76546f14 to your computer and use it in GitHub Desktop.
Save McLarenCollege/78e3e9217799be0eefd2ee6f76546f14 to your computer and use it in GitHub Desktop.

Permutate vowels

Allowed time: 42 mins

The Polish language is famous for its difficult to pronounce words with very few vowels. For example: Pszczyna, a town in Southern Poland, or scczescie, which means happiness.

Your task is to create a function that would generate similar words with very few vowels. Specifically, all possible combinations from the given word, by preserving the consonants in place while swapping the vowel(s) in the word with other vowels to create as many possible permutations.

For example: output for generator (Pszczyna) would produce an array: ['pszczyna', 'pszczyne', 'pszczyni', 'pszczyno', 'pszczynu'].

Vowels are: A, E, I, O, and U

Input: string (length > 0), that consists of only letter characters, of which no more than three vowels.

Output: alphabetically sorted array of words in lowercase, with all possible combinations of vowels.

Example

wordGenerator("Pszczyna")   //  ['pszczyna', 'pszczyne', 'pszczyni', 'pszczyno', 'pszczynu']
wordGenerator("aa")   //  ['aa', 'ae', 'ai', 'ao', 'au', 'ea', 'ee', 'ei', 'eo', 'eu', 'ia', 'ie', 'ii', 'io', 'iu', 'oa', 'oe', 'oi', 'oo', 'ou', 'ua', 'ue', 'ui', 'uo','uu']
wordGenerator("B")   //  ['b']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment