Intermediate Algo Scripting: Pig Latin passed but doubt

Hello everyone, my solution for this challenge was

function translatePigLatin(str) {
  // check for consonants until vowel
  let regex2 = /[^aeiou]*/

  if (/^[aeiou]/.test(str)) {
    return str + "way"
  } else if (regex2.test(str)) {
    return str.replace(str.match(regex2), "") + str.match(regex2) + "ay"


I first checked if the string starts with a vowel, if not, it takes the consonants up until the first vowel and returns the string without that group and with it at the end + “ay”.

My doubt comes from checking what were the solutions provided in the hints section and I’ve found longer ones when it’s usually the opposite case, I come up with longer and more contrived solutions against the more concise soutions in hints. Would anyone provide some feedback to of the code with stricter tests? Am I missing something?

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

Sorry! Will be more careful next time.

Anyway, if it works, it works, you can check that you didn’t miss anything by trying more test cases than those provided, everything that comes to your mind

1 Like