My code fails on translatePigLatin(“rhythm”) test case
- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add
ay
to it.
so translatePigLatin(“rhythm”); should be ythmrhay not rhythmay. Am I wrong?
Your code so far
function translatePigLatin(str) {
if (str.match(/^[^aeioy]/)) {
// consonant
return str.replace(/^([^aeioy]*)(.*)/, "$2$1ay");
}
return str.replace(/^(.*)/, "$1way");
}
translatePigLatin("consonant");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Challenge: Pig Latin
Link to the challenge: