Hi, I wrote the following code for Pig Latin, and it works for the words given as examples. But it seems there is a problem with the first 3 ones: california, paragraphs and glove. If you check them the return gives the same strings as they say in example. However I don’t know what is the problem here.
So please Help!!!
var del = [];
var newstr = "";
var arr = [];
function translatePigLatin(str) {
if ( vowel(str[0]) === true) {
return str +'way';
}
else {
for ( var i=1; i<str.length; i++) {
if( vowel(str[i]) === true) {
newstr = str.substr(i);
for( var j=0; j<i; j++){
del[j] = str[j];
}
for( var x=0; x<newstr.length; x++){
arr[x] = newstr[x];
}
Array.prototype.push.apply(arr,del);
return arr.join("") +"ay";
}
}
}
}
function vowel (l){
var vowels = ["a","e","i","o","u"];
if (vowels.indexOf(l)!==-1)
{
return true;}
else {
return false;}
}
translatePigLatin("paragraphs");