Skip to content

Instantly share code, notes, and snippets.

@samtalks
Created October 1, 2013 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samtalks/6778465 to your computer and use it in GitHub Desktop.
Save samtalks/6778465 to your computer and use it in GitHub Desktop.
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