Skip to content

Instantly share code, notes, and snippets.

@mecampbellsoup
Created September 30, 2013 21:28
Show Gist options
  • Select an option

  • Save mecampbellsoup/6770550 to your computer and use it in GitHub Desktop.

Select an option

Save mecampbellsoup/6770550 to your computer and use it in GitHub Desktop.
require 'awesome_print'
def reverse_each_word(sentence)
reversed_array = sentence.split(" ").collect do |word|
word.reverse
end
reversed_array.join(" ")
end
# reverse_each_word("Hello there, and how are you?")
#=> "olleH ,ereht dna woh era ?uoy"
ap reverse_each_word("Hello there, and how are you?")
#assert_equal "olleH ,ereht dna woh era ?uoy", reverse_each_word("Hello there, and how are you?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment