Skip to content

Instantly share code, notes, and snippets.

@Pcushing
Created June 13, 2012 19:31
Show Gist options
  • Save Pcushing/2925943 to your computer and use it in GitHub Desktop.
Save Pcushing/2925943 to your computer and use it in GitHub Desktop.
Pig Latin with Two Methods
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