Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function translatePigLatin(str) {
  2.  
  3. var regex = /[aeiou]/gi;
  4. // Check if the first character is a vowel
  5. if (str[0].match(regex)) {
  6. return str + 'way';
  7. }
  8. // Find how many consonants before the firs vowel.
  9. var vowelIndice = str.indexOf(str.match(regex)[0]);
  10. // Take the string from the first vowel to the last char
  11. // then add the consonants that were previously omitted and add the ending.
  12. return str.substr(vowelIndice) + str.substr(0, vowelIndice) + 'ay';
  13. }
  14.  
  15. translatePigLatin("consonant");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement