The last case is fails even the result is correct
function translatePigLatin(str) {
var pigLatin = '';
var regex = /[aeiou]+/gi;
if (str[0].match(regex)) {
pigLatin = str + 'way';
}else {
var vowelIndex = str.indexOf(str.match(regex)[0]);
pigLatin = str.substr(vowelIndex) + str.substr(0, vowelIndex) + 'ay';
}
return pigLatin;
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin