So i was messing around with the pig latin challenge and got it working. While checking the ‘get a hint’ section later, I noticed I had a bit of a different approach. I’m curious what you think of it
function translatePigLatin(str) {
var regex = /([^aeiou]+)(\w+)/;
var testRegex = /^[aeiou]/;
var startWithVowel = testRegex.test(str);
var hasVowel = /[aeiou]/.test(str);
if (!startWithVowel && hasVowel) {
return str.replace(regex, '$2$1') + 'ay';
} else if (startWithVowel && hasVowel) {
return str + 'way';
} else {
return str + 'ay';
}
}
translatePigLatin("qwfgt");