As far as I can tell, the code that I have written for the Pig Latin challenge is working and returning the values expected for each test.
const vowels = ["a", "e", "i", "o", "u"];
function translatePigLatin(str) {
var count = countInitialConsonants(str);
if (startsWithVowel(str)) {
str += "way";
} else {
var letters = str.split('');
var consonants = letters.splice(0, count).join('');
str = letters.join('') + consonants + "ay";
}
return str;
}
function startsWithVowel(word) {
return vowels.includes(word[0]);
}
function countInitialConsonants(word) {
var chars = word.split('');
for (var i = 0; i < chars.length; i++) {
if (vowels.indexOf(chars[i]) > -1) {
return i;
}
}
return 0;
}
translatePigLatin("glove");
Am I missing something, or is this a bug?