Created
June 17, 2013 22:03
-
-
Save joegiralt/5800910 to your computer and use it in GitHub Desktop.
reverse method
This file contains hidden or 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
# From [Rubeque](http://rubeque.com/problems/reverse-each-word) | |
# Write a method that takes a sentence and returns it with each word reversed in place. | |
# ruby | |
# reverse_each_word.rb | |
# Write a method that takes a sentence and returns it with each word reversed in place. | |
# A String has many methods that can be called on it: | |
# http://www.ruby-doc.org/core-1.9.3/String.html | |
def reverse_each_word(sentence) | |
sentence.split(" ").reverse.join(" ").reverse | |
end | |
# reverse_each_word("Hello there, and how are you?") | |
#=> "olleH ,ereht dna woh era ?uoy" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment