Skip to content

Instantly share code, notes, and snippets.

@jkaihsu
Created March 7, 2013 08:20
Show Gist options
  • Select an option

  • Save jkaihsu/5106416 to your computer and use it in GitHub Desktop.

Select an option

Save jkaihsu/5106416 to your computer and use it in GitHub Desktop.
Write a method reverse_words which takes a sentence as a string and reverse each word in it.
def reverse_words(str)
words = str.split(' ')
reverse_str = []
words.length.times do |i|
reverse_str[i] = words[i].reverse
end
return reverse_str.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment