Created
June 13, 2012 19:31
-
-
Save Pcushing/2925943 to your computer and use it in GitHub Desktop.
Pig Latin with Two Methods
This file contains hidden or 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(word) | |
start_point = vowels_start(word) | |
end_point = word.length - 1 | |
if start_point == 0 | |
word + "ay" | |
else | |
word[start_point, end_point] + word[0, start_point] + "ay" | |
end | |
end | |
def vowels_start(word) | |
vowels = ["a", "e", "i", "o", "u"] | |
if vowels.include?word[0] | |
0 | |
elsif (vowels.include?word[1]) && (word[0,2] != "qu") | |
1 | |
elsif vowels.include?word[2] | |
2 | |
elsif vowels.include?word[3] | |
3 | |
else | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment