translatePigLatin problem with some some words for testing case

any idea in this code about of how could to resolve the problem for the case test?

translatePigLatin(“glove”) ; translatePigLatin(“schwartz”) ; translatePigLatin(“rhythm”);

any suggestion is appreciated :slight_smile:

 translatePigLatin(str) {
     let regex = /^[aeiou]{1}/

        str = str.replace(/.{0}$/, 'way')
        str = str.slice(0, 10) + str[0] + str.slice(10);
        str = str.replace(/.{0}$/, 'ay')
  return str;

function translatePigLatin(str) {
  let regex = /^[aeiou]{1}/ , text;

   text = str.replace(/.{0}$/, 'way')
  } else {
      //get the first consonant or the group of consonants before first vowel
      //if any
      let nonWowelGroup = str.match(/[^aeiou]+/)[0];
      //concatenate the text after the first consonant or the group to the  group and suffix "ay"
      text = str.slice(nonWowelGroup.length) + nonWowelGroup + "ay";  
  return text;


@alb0084, I literally have doubts about every line of your code. I suggest you start with easier problems and try this one a bit later.

Little hint for you:
If you want to add one string to another (concatenate), you can simply:

const a = 'a';
const b = 'way';
const concat = a + b;

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.

@RandellDawson in my own solution before to posted this once in regex pattern i used this pattern matching -> ^(a|e|i|o|u){1} this seems to not work in my javascript code indeed when i try to call function test on my function test, the function test() return always true,whilst this ^[aeiou]{1} clearly work…could you tell me why may this happen?

I don’t see where you posted the regex you mention above that did not work. The reason it would not work, is that you have a space between the ) and the {1.

@RandellDawson sorry i do not pay attention for spacing but actually without the space does not work anyway…or better the function test() of regex’s object return always true ( but for some strange motive in online regex editor this go well).

-> here there link of my test…,console

I don’t see {1}. I see {}.

@RandellDawson here my test code… is what i said previously:

function functionTest(str) {
var word = str ;
var re = new RegExp("(a|e|i|o|u){1}");
return str;

here “nnnnojjj” the matchin pattern regex would be returned false because in the first index of my string there is not any Vowel…how come it returns anyway true?
here there is the link about my test.

Your regex is not checking if the first character is a vowel. You are missing the ^ anchor at the beginning to designate the string should start matching at the beginning of the string.

All clear…thanks a lot @RandellDawson .

sorry @GeorgeCrisan what difference between /^[aeiou]{1}/ and /[^aeiou]{1}/?

The first one checks that the first character is a vowel. The second one checks if there is one character (anywhere in the string) which is not a vowel.

1 Like

What if you do:

let match = (str.match(/^[^aeiou]+/) || [''])[0];
return str.slice(match.length) + match + (match.length ? 'ay' : 'way');

There’s one even sexier solution with .replace()

@snigo you are too high skilled mate!..before to think that solution at least it me takes 100 years. :rofl:

3 posts were split to a new topic: Using regex with Search and Replace challenge