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");