function translatePigLatin(str) {
str=str.split('');
var newStr="";
if (str.indexOf('a')===0) {
str.push('w','a','y');
return str.join('');
}
else if (str.indexOf('e')===0) {
str.push('w','a','y');
return str.join('');
}
else if (str.indexOf('i')===0) {
str.push('w','a','y');
return str.join('');
}
else if (str.indexOf('o')===0) {
str.push('w','a','y');
return str.join('');
}
else if (str.indexOf('u')===0) {
str.push('w','a','y');
return str.join('');
}
else {
newStr=str.shift();
}
if (str.indexOf('a')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('e')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('i')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('o')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('u')===0) {
str.push(newStr,'a', 'y');
}
else {
newStr+=str.shift();
if (str.indexOf('a')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('e')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('i')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('o')===0) {
str.push(newStr,'a', 'y');
}
else if (str.indexOf('u')===0) {
str.push(newStr,'a', 'y');
}
}
return str.join('');
}
This was embarassingly bad . . .