Skip to content
Advertisement

Adding string after each vowel

I am currently on a project to develop a small, fun program that takes a name as an input and returns the name with the string “bi” after each vowel in the name.

I am encountering the problem that my program runs in an infinite loop when I have a name that has same the same vowel twice, for example: the name “aya”. technically it should return “abiyabi”

JavaScript

I thought first it is a problem with the first letter being a vowel. but I added an if statement that should solve that. I’m honestly out of answers now, and seeking help. You guys might see something I don’t see.

Advertisement

Answer

Build the Bobied name independent of the user-submitted name. Also note that strings are iterables in Python and there’s no need to convert the user-submitted name to a list.

JavaScript

Now, if you want to avoid the loops and conditionals, or have large input: use str.translate(). First make a translation table, just a dict which maps vowels to bobified vowels. Then call translate() on the name to be bobified.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement