Created
October 11, 2013 16:04
-
-
Save irmiller22/6937427 to your computer and use it in GitHub Desktop.
reverse_word.rb
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) | |
temp_array = [] | |
array = sentence.split(//) | |
array.length.times do | |
temp_array.push(array.pop) | |
end | |
array = temp_array.join | |
array | |
end | |
reverse_each_word("hello") | |
def reverse_each_word(sentence) | |
sentence.split(" ").collect { |word| word.reverse.join(" ") } | |
end | |
def reverse_each_word(sentence) | |
result = [] | |
sentence.split(" ").each do |word| | |
result << word.reverse | |
end | |
result.join(" ") | |
end | |
def reverse_each_word(sentence) | |
sentence.reverse.split(" ").reverse.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment