Pig Latin Test Case is not passing

The last case is fails even the result is correct


function translatePigLatin(str) {
  var pigLatin = '';
  var regex = /[aeiou]+/gi;
  if (str[0].match(regex)) {
    pigLatin = str + 'way';
  }else {
    var vowelIndex = str.indexOf(str.match(regex)[0]);
    pigLatin = str.substr(vowelIndex) + str.substr(0, vowelIndex) + 'ay';
  return pigLatin;


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36.

Link to the challenge:

Because of the last statement rule that is the without vowels.

How should I finish the last test?

Hey HooriaHic, Look my code and it’s successfully accepted.

function translatePigLatin(str) {
  return str.replace(/^([aeiou])(.*)/, '$1$2way').replace(/^([^aeiou]+)(.*)/, '$2$1ay');


Hope this helpful

1 Like

Thanks, SpadeX
:+1: your code is successfully accepted