Skip to content

Instantly share code, notes, and snippets.

@rayning0
Last active December 24, 2015 08:59
Show Gist options
  • Select an option

  • Save rayning0/6774278 to your computer and use it in GitHub Desktop.

Select an option

Save rayning0/6774278 to your computer and use it in GitHub Desktop.
Reverse each word
def reverse_each_word(sentence)
sentence.split.map {|word| word.reverse}.join(' ')
end
# reverse_each_word("Hello there, and how are you?")
# => "olleH ,ereht dna woh era ?uoy"
puts reverse_each_word("Hello there, and how are you?")
puts reverse_each_word("Just be creative, create a bunch of fake data.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment