Created
August 30, 2016 06:10
-
-
Save danielpowell4/55b54b4fcde91c3b4f978e7da2730920 to your computer and use it in GitHub Desktop.
Pig latin translation sans handling for vowels or "Qu"-type exceptions
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
# gsub solution | |
def pig_it text | |
text.gsub(/(\w)(\w+)*/, '\2\1ay') | |
end | |
# interpolation check for word | |
def pig_it text | |
text.split.map{|word| word =~ /\w/ ? "#{word[1..-1]}#{word[0]}ay" : word}.join(" ") | |
end | |
# another solution check for punctuation | |
def pig_it text | |
text.split.map { |t| '!?.'.include?(t) ? t : t[1..-1] + t[0] + 'ay' }.join ' ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment