Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function translatePigLatin(str) {
- var regex = /[aeiou]/gi;
- // Check if the first character is a vowel
- if (str[0].match(regex)) {
- return str + 'way';
- }
- // Find how many consonants before the firs vowel.
- var vowelIndice = str.indexOf(str.match(regex)[0]);
- // Take the string from the first vowel to the last char
- // then add the consonants that were previously omitted and add the ending.
- return str.substr(vowelIndice) + str.substr(0, vowelIndice) + 'ay';
- }
- translatePigLatin("consonant");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement