This works for me but I noticed the task was meant to be solved with regular expression, is there a performance issue between using regular expressions and loops?
Your code so far
function translatePigLatin(str) {
for (let i = 0; i < str.length; i++)
{
if (str.charAt(i) === 'a'|| str.charAt(i) === 'e'|| str.charAt(i) === 'i'||
str.charAt(i) === 'o'|| str.charAt(i) === 'u')
{
if (i === 0)
{
return str+"way";
}
return str.slice(i,str.length)+str.slice(0,i)+"ay";
}
}
return str+"ay";
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin