Pig Latin "Should handle words where the first vowel comes in the end of the word."

Tell us what’s happening:

Hi ! I’m stuck with the following test “Should handle words where the first vowel comes in the end of the word.”

Could be I am not understanding what is referring to but I think I cover all the cases with my current code.

Sorry if its a bit messy, just trying to past all the test before optimising it :stuck_out_tongue:

Have you found any issue passing that specific test ?
Your code so far

function translatePigLatin(str) {
  const aStr = str.split('')
  const isVowel = char => ['a','e','i','o','u'].indexOf(char) !== -1
  const isThereAVowel = aStr.filter( char => isVowel(char)).length
  const lastCharIsFirstVowel = isThereAVowel === 1 && isVowel(str[str.length -1])

  if (isVowel(str[0])){
    return `${str}way`
  } else if (!isVowel(str[0]) && !isVowel(str[1]) && isThereAVowel && !lastCharIsFirstVowel) {
    return `${str.slice(2)}${str[0]}${str[1]}ay`
  } else if (!isThereAVowel) {
    return `${str}ay`
  } else if (lastCharIsFirstVowel){
    return `${str.slice(-1)}${str.slice(0,str.length - 1)}ay`
  } else {
    return `${str.slice(1)}${str[0]}ay`


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.

Link to the challenge:

What happens if the vowel is the fourth character? Or the second to last?

Hi !

You are right , in all those conditions won’t work. I guess I will try to loop through the string and consider more scenarios than the ones listed in the exercise.

Thank you