Good evening, just passed “Pig Latin” and wanted to ask, does my code is good enough to go further? Asking cuz I don’t feel very comfortable at this point and I have no idea if i will break through at the future.
Thanks in advance!
Code:
function translatePigLatin(str) {
str = str.split("");
var vowels = 'aeiou';
for (var i=0; i<str.length; i) {
if (!/a|e|i|o|u/.test(str)) {
str.push("ay");
break;
} else if (vowels.indexOf(str[i]) == -1) {
str.push(str[i]);
str.shift();
if (vowels.indexOf(str[i]) !== -1) {
str.push("ay")
break;
}
} else if (vowels.indexOf(str[i]) !== -1) {
str.push("way");
break;
}
}
str = str.join('');
console.log(str);
return str;
}
translatePigLatin("california");
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/