Anybody can tell me what the meaning of “ /^[^aeiou]+/
” of the second line is?
Since “^” means negative, then" [^aeiou] +
" means consonant or consonant cluster, and “^[^aeiou]+
” means positive that are vowels? and what about “y” as it is a vowel sometimes? Anybody can help me with this? Thanks
Question:
Pig Latin
Pig Latin is a way of altering English Words. The rules are as follows:
-
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. -
If a word begins with a vowel, just add
way
at the end.
Translate the provided string to Pig Latin. Input strings are guaranteed to be English words in all lowercase.
Your code so far
function translatePigLatin(str) {
let consonantRegex = /^[^aeiou]+/;
let myConsonants = str.match(consonantRegex);
return myConsonants !== null
? str
.replace(consonantRegex, "")
.concat(myConsonants)
.concat("ay")
: str.concat("way");
}
translatePigLatin("consonant");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36
Challenge: Pig Latin
Link to the challenge: