[Intermediate Algorithm Scripting] Pig Latin Intermediate solution not working + advanced go infinite loop + easier solution

The intermediate solution doesn’t work without vowels for example: translatePigLatin(“bcdf”); // output “too much recursion”

The advanced solution goes in infinite loop with the same input translatePigLatin(“bcdf”);

And I think I have a much simpler solution (not sure since I am still a noob hehe)

function translatePigLatin(str) {
  let vowel = /^[aeiou]/i;
  let conson = /^[bcdfghjklmnpqrstvwxyz]+/i;
  // Check if the string start with a vowel and then return string + way
  // Otherwise replace the first consonant by empty char then add the first consonant + ay at the end
  vowel.test(str) ? str += 'way' : str = str.replace(conson.exec(str), '') + str.match(conson)[0] + 'ay';
  return str;
1 Like

Thank you for helping make FCC better. Bugs should always be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.