Pig Latin Challenge, Bug?

Hi there!! The Main problem is maybe a Bug, when I run the challenge I am not allowed to pass it because the code “Should handle words without vowels.”, btw I try a word without a vowel and… it’s ok! When I change the commented code! Is there a difference in the returned array using “Array.from(str)” or str.split("") ? Thank you!!

Your code so far


function translatePigLatin(str) {
  let result= [];
  let asd;
  function esVocal (letra){
    if (!/^[aeiou]/.test(letra)){
      return true;
    } else { return false;}
  }
  function definitivo (str) {
    if(esVocal(str.charAt(0))){
//This is what I change and it is Ok for the challenge
//      result= str.split("");
// in instead of the line below 
      result= Array.from(str);
      while (esVocal(result[0])){
        asd=result.shift();
        result.push(asd);
      }
      return result;

     } else {
       str= str.concat('w');
       return Array.from(str);}
  }
  return definitivo(str).join("").concat("ay");
  }
console.log(translatePigLatin("x"));

Your browser information:

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

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

Words without vowels shouldn’t be shifted and they should still get the “ay” at the end.
‘bzzz’ for example would be ‘bzzzay’.

1 Like

I thought that maybe there was a differente between Array.from and split(""), but I had an error in the code…

I forgot a " ! " in the while loop:

while (!esVocal(result[0])){
asd=result.shift();
result.push(asd);
}
return result;

Thank you Ariel!

Good job figuring it out. Happy coding!

Result OK
function translatePigLatin(str) {
let result= ;
let asd;
let patron=!/[aeiou]/
function esConsonante (letra){
if (!/[aeiou]/.test(letra)){
return true;
} else { return false;}
}
function definitivo (str) {
if(!esConsonante(str.charAt(0))){
return str + “way”;
} else {
result=Array.from(str);
while (str.search(/[aeiou]/)===-1){
return result.join("") + “ay”;
};
while (esConsonante(result[0])){
asd=result.shift();
result.push(asd);
};
return result.join("") + “ay”;
}
}
return definitivo(str)};
console.log(translatePigLatin(“california”));
console.log(translatePigLatin(“bzzz”));
console.log(translatePigLatin(“bzzz”));