function translatePigLatin(str) {
let regex = /^[aeiou]{1}/ , text;
if(regex.test(str)){
text = str.replace(/.{0}$/, 'way')
} else {
//get the first consonant or the group of consonants before first vowel
//if any
let nonWowelGroup = str.match(/[^aeiou]+/)[0];
//concatenate the text after the first consonant or the group to the group and suffix "ay"
text = str.slice(nonWowelGroup.length) + nonWowelGroup + "ay";
};
return text;
}
translatePigLatin("california");
@camperextraordinaire in my own solution before to posted this once in regex pattern i used this pattern matching -> ^(a|e|i|o|u){1} this seems to not work in my javascript code indeed when i try to call function test on my function test, the function test() return always true,whilst this ^[aeiou]{1} clearly work…could you tell me why may this happen?
@camperextraordinaire sorry i do not pay attention for spacing but actually without the space does not work anyway…or better the function test() of regex’s object return always true ( but for some strange motive in online regex editor this go well).
function functionTest(str) {
var word = str ;
var re = new RegExp(“(a|e|i|o|u){1}”);
console.log(re.test(word));
return str;
}
functionTest(“nnnnojjj”);
here “nnnnojjj” the matchin pattern regex would be returned false because in the first index of my string there is not any Vowel…how come it returns anyway true?
here there is the link about my test.