Last active
December 24, 2015 08:59
-
-
Save rayning0/6774278 to your computer and use it in GitHub Desktop.
Reverse each word
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
| 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