function vowelCheck(str,index){
if(str[index]=='a' || str[index]=='e' || str[index]=='i' || str[index]=='o' || str[index]=='u'){
return true;
}
}
function translatePigLatin(str) {
//vowel case
str = str.toLowerCase();
var arr = [];
var indexCount = 0;
if(vowelCheck(str,0)){
return str+"way";
} else {
arr.push(str[0]);
indexCount++;
for(var i=1; i<str.length; i++){
if(!vowelCheck(str,i)){
arr.push(str[i]);
indexCount++;
} else {
break;
}
}
return str.substr(indexCount,str.length)+arr.join('')+"ay";
}
return arr;
}
translatePigLatin("consonant");
No comments:
Post a Comment