[FEEDBACK] Pig Latin

[FEEDBACK] Pig Latin
0

#1

Hello guys, since this algorithm actually gave me some headache, i wanted to ask for some feedback on my code:

function translatePigLatin(str) {
  pattern = /[aeiou]/gi;
  vowelPos = pattern.exec(str).index; // return the position of the first vowel found by the regex.exec
  
  if(vowelPos === 0) {
    str = str + "way";
  } else {
    consCluster = str.substr(0, vowelPos);
    str = str.substr(vowelPos) + consCluster + "ay";
  }
  
  return str;
  
}

translatePigLatin("consonant");

#2

That looks like basically what I did. I’m sure there’s more than one way to skin that atcay, but this works.

Now, how does it handle the obscure English words where w is a vowel, like crwth or cwm? :wink:


#3

Badly. Really badly.