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");
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
@RandellDawson 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?
I don’t see where you posted the regex you mention above that did not work. The reason it would not work, is that you have a space between the ) and the {1.
@RandellDawson 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).
@RandellDawson here my test code… is what i said previously:
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.
Your regex is not checking if the first character is a vowel. You are missing the ^ anchor at the beginning to designate the string should start matching at the beginning of the string.
The first one checks that the first character is a vowel. The second one checks if there is one character (anywhere in the string) which is not a vowel.