Created
October 1, 2013 13:30
-
-
Save samtalks/6778465 to your computer and use it in GitHub Desktop.
This file contains 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) | |
arr = [] | |
sentence.split.map do |word| | |
reversed = "" | |
i = 0 | |
while i < word.length | |
reversed << word[word.length-(i+1)] | |
i += 1 | |
end | |
arr << reversed | |
end | |
puts arr = arr.join(" ") | |
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