Created
June 14, 2012 20:11
-
-
Save shereefb/2932630 to your computer and use it in GitHub Desktop.
Implementations of pig latin in ruby
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(word) | |
# vowels = ["a","e","i","o","u"] | |
# if !vowels.include?(word[0]) | |
# if word[0..1] == "qu" | |
# word[2..-1]+"quay" | |
# else | |
# counter = 0 | |
# while !vowels.include?(word[counter]) | |
# counter += 1 | |
# end | |
# word[counter..-1] + word[0..(counter-1)] +"ay" | |
# end | |
# else | |
# word+"ay" | |
# end | |
# end | |
def translate(word) | |
index = (word.start_with?('qu') ? 2 : word =~ /[aeiou]/) | |
# if word.start_with?('qu') | |
# index = 2 | |
# else | |
# index = word =~ /[aeiou]/ | |
# end | |
index ||= 0 | |
if index == 0 | |
word + 'ay' | |
else | |
word[index..-1] + word[0..index-1] + 'ay' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment