Created
October 13, 2013 16:28
-
-
Save andersr/6964166 to your computer and use it in GitHub Desktop.
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
# Write a method that takes a sentence and returns it with each word reversed in place. | |
my_sentence = "This is a sentence we'll use to reverse each word in the sentence." | |
def reversed_words(sentence) | |
reversed_words_sentence = sentence.split(/[" ",.]/).collect do |word| | |
word.reverse | |
end | |
reversed_words_sentence.join(" ") | |
end | |
puts reversed_words(my_sentence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment