Skip to content

Instantly share code, notes, and snippets.

@RickArora
Created December 25, 2018 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickArora/f8f910b6e9d82daf60f76c45eb7249b2 to your computer and use it in GitHub Desktop.
Save RickArora/f8f910b6e9d82daf60f76c45eb7249b2 to your computer and use it in GitHub Desktop.
def translate(translate_this)
counter = 0
translated_word = ""
translate_this.split.each do |word|
if ((word[0] == "a" || word[0] == "i" || word[0] == "o" || word == "u" || word == "e") && counter > 1)
translated_word = translated_word + word + "ay "
counter += 1
elsif (word[0] == "a" || word[0] == "i" || word[0] == "o" || word == "u" || word == "e")
translated_word = translated_word + word + "ay"
counter += 1
else
translated_word = translated_word + word[1..word.length-1] + word[0] + "ay "
counter += 1
end
end
if translated_word.split.length == 1
return translated_word
else
return translated_word[0..translated_word.length-1]
end
end
@RickArora
Copy link
Author

  1. #translate translates a word beginning with a consonant
    Failure/Error: expect(s).to eq("ananabay")

    expected: "ananabay"
    got: "ananabay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:34:in `block (2 levels) in <top (required)>'

  2. #translate translates a word beginning with two consonants
    Failure/Error: expect(s).to eq("errychay")

    expected: "errychay"
    got: "herrycay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:39:in `block (2 levels) in <top (required)>'

  3. #translate translates two words
    Failure/Error: expect(s).to eq("eatay iepay")

    expected: "eatay iepay"
    got: "ateay iepay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:44:in `block (2 levels) in <top (required)>'

  4. #translate translates a word beginning with three consonants
    Failure/Error: expect(translate("three")).to eq("eethray")

    expected: "eethray"
    got: "hreetay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:48:in `block (2 levels) in <top (required)>'

  5. #translate counts 'sch' as a single phoneme
    Failure/Error: expect(s).to eq("oolschay")

    expected: "oolschay"
    got: "choolsay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:53:in `block (2 levels) in <top (required)>'

  6. #translate counts 'qu' as a single phoneme
    Failure/Error: expect(s).to eq("ietquay")

    expected: "ietquay"
    got: "uietqay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:58:in `block (2 levels) in <top (required)>'

  7. #translate counts 'qu' as a consonant even when it's preceded by a consonant
    Failure/Error: expect(s).to eq("aresquay")

    expected: "aresquay"
    got: "quaresay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:63:in `block (2 levels) in <top (required)>'

  8. #translate translates many words
    Failure/Error: expect(s).to eq("ethay ickquay ownbray oxfay")

    expected: "ethay ickquay ownbray oxfay"
    got: "hetay uickqay rownbay oxfay "

    (compared using ==)

    ./spec/04_pig_latin_spec.rb:68:in `block (2 levels) in <top (required)>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment