Hey. Currently stuck on Pig Latin - “Should handle words without vowels”. My thought is that in case of word without vowel the function should return this word +ay. But it doesn’t pass the test. Can you please take a look at my code and tell what am I doing wrong?
function translatePigLatin(str) {
let regex = /(^[^aouiey]{1,})([a-z]{1,})/;
if (/[auieo]/.test(str[0])) {
return str + 'way'
} else if (/[auieoy]/g.test(str) === false) {
return str + 'ay';
} else {
return str.replace(regex, '$2$1' + 'ay');
}
}
translatePigLatin("cdzx"); //returns cdzxay