Pig Latin Solution correct in repl it but won't pass tests in FCC?

Hi,
Here is my solution for the pig latin question in the Intermediate algorithms section:

function translatePigLatin(str) {

 let regex = /^[^aeiou]+/

  let consonantResult = "";
  
  if (regex.test(str)) {
    consonantResult = str.match(regex)
    return str.replace(consonantResult, " ").split(",").concat(consonantResult, 'ay').join("")
  } else {
    return str.split(",").concat('way').join("")
  }
}

When running this in a js environment (repl it) I get the output as required in each test as per the FCC page for this question.
However, when I try to run it in the FCC page the only tests that pass are for ‘algorithm’ and ‘eight’.
I’ve been trying to figure this out but i just can’t, as far as repl it is concerned i’m getting the required output
Can anyone suggest where the problem is here?
Any help appreciated,
Many thanks,
Charlotte

the last test, for example, your output is " rhythmay"

the extra space should not be there

1 Like

Ha, no way! Sometimes it’s the tiniest things, have changed it to str.replace(consonantResult, “”) and now all are passing
Well, spotted, thanks a lot! :grin: