Dear All,
my first post in here I have solved Pig Latin quiz using for
loop, to do that after iteration I have reset the counter and use continue
(please see the code below). My question is whether is such a loop handling acceptable?
function translatePigLatin(str) {
let strArray = str.split('');
let regex = /[aeiou]/;
if(regex.test(strArray[0])) {
return str + 'way';
} else if(regex.test(str) === false) {
return str + 'ay';
} else {
for(let i = 0; i < strArray.length; i++) {
if(!regex.test(strArray[i])) {
let tempLetter = strArray[i];
strArray.splice(0,1);
strArray.push(tempLetter);
i=-1; continue;
} else {
return strArray.join('') + 'ay'; }
}
}
}
translatePigLatin("consonant");
Thank you in advance for your comments.
Cheers,
Ewa