Pig Latin test problem

I have been developing this exercise called Pig Latin, and my solution:

function translatePigLatin(str) {

let vocales=/[a,e,i,o,u]/gi
let regex = /([bcdfghjklmnñpqrstvxyz]+)(\w+)/;

if(str[0].match(vocales)){
return str+‘way’
}else{

return str.replace(regex, “$2$1”) + ‘ay’
}
}

returns the same as the solutions given by FCC on get a hint; so I would like you please check it and solve all the problem with it. Because my test can’t pass correctly

Pd: I really Love FreeCodeCamp.!

Your code so far


function translatePigLatin(str) {

 let vocales=/[a,e,i,o,u]/gi
  let regex = /([bcdfghjklmnñpqrstvxyz]+)(\w+)/;

if(str[0].match(vocales)){
  return str+'way'
}else{
  
  return str.replace(regex, "$2$1") + 'ay'
}
}

translatePigLatin("consonant");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin

You must handle consonant clusters, example: cdfa should transform into acdfay, move cdf to the end and add ay.

I think the challenges tests could be improved by adding more examples.

yeah; my code do that

Your code actually handle my example just fine.

Error: Should handle words without vowels.
Problem: Your code is not handling words without vowels, please log the word rhythm, your code gave us mrhythay, the correct answer would be rhythmay.
What’s wrong: Your regex works fine for when there’s a vowel in the word, but when it doesn’t, it will grab the last character and insert it into the beginning of the result.
Answer: Check if there’s a vowel in the word and handle it by just adding an ay to its end.

Error: Should handle words where the first vowel comes in the end of the word.
Problem: Please log the word shwa, your code gave us washay, the correct answer would be ashway.
What’s wrong: You forgot one of those characters in your regex: /([bcdfghjklmnñpqrstvxyz]+)/
Answer: Fix your regex to have the complete alphabet.

Sorry for the delay and the bad example in the last post.

1 Like