Skip to content

Instantly share code, notes, and snippets.

@danielpowell4
Created August 30, 2016 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpowell4/55b54b4fcde91c3b4f978e7da2730920 to your computer and use it in GitHub Desktop.
Save danielpowell4/55b54b4fcde91c3b4f978e7da2730920 to your computer and use it in GitHub Desktop.
Pig latin translation sans handling for vowels or "Qu"-type exceptions
# 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