-
-
Save RickArora/f8f910b6e9d82daf60f76c45eb7249b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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)>'
#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)>'
#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)>'
#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)>'
#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)>'
#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)>'
#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)>'
#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)>'