question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
delbertleggcommented, Feb 1, 2017

I’d be happy to fix it. I’ll work on it this evening…thanks!

0reactions
masters-georgecommented, Mar 28, 2017

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found