Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created October 11, 2013 16:04
Show Gist options
  • Save irmiller22/6937427 to your computer and use it in GitHub Desktop.
Save irmiller22/6937427 to your computer and use it in GitHub Desktop.
reverse_word.rb
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