paragraphs & california should work?
while i know this isn’t valid solution since it doesn’t handle words without vowels, but from what I understand it should handle words like paragraphs and California.
it is handling the rest of the tests but for these 2 words it is acting weirdly.
I’m trying to understand how these dollar signs work with regex and replace so let me know
thanks!
**Your code so far**
function translatePigLatin(str) {
let result = "";
if(str[0] == 'a' || str[0] == 'e' || str[0] == 'i' || str[0] == 'o' || str[0] == 'u') {
result = str.concat("way");
}
else {
result = str.replace(/([a-zA-Z]+)([a||e||i||o||u])([a-zA-Z]+)/, "$2$3$1ay")
}
return result;
}
console.log(translatePigLatin("paragraphs"));
translatePigLatin("consonant");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Pig Latin
as i understand it should first find consonants, until it finds a vowel (or vowels but in the case I didn’t add the +) and then the rest of the consonants, in this order and then switch them like this: vowel(s)-lettersaftervowel-lettersbeforevowel+ay
but now I realize that I should’ve excluded the vowels from the first section which includes the entire alphabets thus why it doesn’t take the letters before the first vowel as the 1st part ($1), correct?