So i’m trying to do what the challenge says, moving the first consonants to the end of the string with an "ay"
and it works but but i can’t find a way to apply this algorithm when it needs to move more than one consonant from the first.
ex :
translatePigLatin("glove") should return "oveglay".
this algo is only working for one letter to move to the end.
Can someone point out where i’m making any mistake.
Here is the code :
function translatePigLatin(str) {
var arr = str.split("");
var newStr="";
for(let i=0;i<arr.length;i++){
if(arr[i]==='a'||arr[i] === 'e'||arr[i] === 'i'||arr[i] === 'o'||arr[i] === 'u'){
return str+"way";
}else{
newStr=str.substr(a[i]);
return newStr+arr[i]+"ay";
}
}
}
translatePigLatin("consonant");
Link to the challenge:
[@camperextraordinaire little help plz]