Hey all,
I’m having some confusion as to why my solution to the Pig Latin Intermediate Algorithm is not working. It tests positive for everything but glove (oveglay). Can anyone tell me why?
function translatePigLatin(str) {
let newStr = "";
let regex = /[aeiou]/gi;
let strWay = "way";
let strAy = "ay";
if(str[0].match(regex)) {
newStr = str.concat(strWay);
} else if (str[0].match(regex) === null){
let arr = str.split("");
let letter = arr.splice(0,1);
newStr = arr.join("").concat(letter).concat(strAy);
} else {
let arr = str.split("");
let letter = arr.splice(0,2);
newStr = arr.join("").concat(letter).concat(strAy);
}
return newStr;
}
translatePigLatin("consonant");