Tell us what’s happening:
I’m working on the pig latin problem and need help with Regex. If this is the wrong way to approach this problem, please redirect me.
when testing for Regex it returns true or false, right? so if I’m looking for the first instance of a vowel, is there a way I could test where it would give me the index on split where the Regex was met. also I forgot how to test split for the regex1. If I could find the index of where the first vowel occurs, I can use 2 slices of str and concat them with the ‘ay’ to get the correct answer.
Your code so far
function translatePigLatin(str) {
let split = [...str];
let regex1 = /a|i|e|o|u|y/;
let firstVowel = [firstA, firstE, firstI, firstO, firstU];
console.log(firstVowel);
if (str.startsWith('a') || str.startsWith('e') || str.startsWith('i') || str.startsWith('o') || str.startsWith('u') || str.startsWith('y')) {
return str + "way";
} else{
return str;
}
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin