Pig Latin Challenge - tests do not cover edge cases
See original GitHub issue@Greenheart I was reviewing old submissions and noticed that my implementation did not correctly return words that are all consonants (such as “my”) or where the first vowel appears at index > 2 (such as “phrase”), but did pass all the tests provided. Recommend adding these edge cases to the test suite (can get crazy like adding “schwartz” or something like that).
Offending solution (no judgement…I was learning JS at the time 😃 ):
function translatePigLatin(str) {
var vowels = ['a', 'e', 'i', 'o', 'u'];
for (var i = 0; i < vowels.length; i++) {
if (str.charAt(0) == vowels[i]) {
str+= "way";
break;
}
else if (str.charAt(1) == vowels[i]) {
str = str.slice(1) + str.charAt(0) + "ay";
break;
}
else if (str.charAt(2) == vowels[i]) {
str = str.slice(2) + str.substr(0, 2) + "ay";
break;
}
}
return str;
}
translatePigLatin("phrase");
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
freeCodeCamp Challenge Guide: Pig Latin
Pig Latin Problem Explanation You need to create a program that will translate from English to Pig Latin. Pig Latin takes the first ......
Read more >I tried this pig latin challange still failed two test cases what ...
I tried this pig latin challange still failed two test cases what might be problem? Pig Latin +50 XP You have two friends...
Read more >Discuss Simple Pig Latin - Codewars
I solved this, but because there's no space before the exlamation point, the test case fails two of the tests that involve punctuation....
Read more >Translating to Pig Latin with Ruby | by Emily Nielsen - Medium
One way to break the challenge into smaller chunks is to create a helper method that can translate each word into Pig Latin....
Read more >Pig Latin - TestFirst.org
(There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d be happy to fix it. I’ll work on it this evening…thanks!
The instructions for the beta version of the challenge also need to tell the camper how to handle words that have no vowels (e.g. merely append “ay” at the end of the word).