I’m struggling to pass the last two tests for this challenge and I can’t figure out why. I’ve tested both of the last cases in chrome console and seem to not have any issues. I know my code isn’t very clean so I apologize beforehand. Here is my code:
function translatePigLatin(str) {
let testVowel = [];
let testConsonant =[];
let editArr = str.split("");
testVowel = str.match(/[aeiou]/i);
testConsonant = str.match(/[b-df-hj-np-tvxz]+/i);
if (testVowel == null){
return str;
}
if (testVowel != null && str.indexOf(testVowel[0]) == 0 ){
return str + "way";
}
editArr.splice(editArr.indexOf(testConsonant[0][0]),testConsonant[0].length)
editArr.push(testConsonant[0],'a','y');
str = editArr.join("");
return str;
}