Forgive me fCC for i have sinned šŸ™

by solving Pig Latin legacy JS challenge using array methods and a bunch of ifs:

function translatePigLatin(str) {
let vow = [ā€˜aā€™,ā€˜eā€™,ā€˜iā€™,ā€˜oā€™,ā€˜uā€™];
let arr = str.split(ā€˜ā€™);
if (arr.every((ltr) => !vow.includes(ltr))) {
arr.push(ā€˜aā€™, ā€˜yā€™);
return arr.join(ā€˜ā€™);
}
if (!vow.includes(arr[0])) {
while (!vow.includes(arr[0])) {
arr.push(arr[0]);
arr.shift()
}
arr.push(ā€˜aā€™, ā€˜yā€™);
} else {
arr.push(ā€˜wā€™, ā€˜aā€™, ā€˜yā€™);
}
return arr.join(ā€˜ā€™);
}

I will remediate this ā€¦ later.

1 Like

While it is not graceful by any means, it is by far from the worst solutions I have ever seen on a challenge.

1 Like