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