Ruby Write Method Called Reverseeachword Takes String Argument Sentence Returns Sentence W Q43892382
RUBY!
Write a method called reverse_each_word that takes in a stringargument of a sentence and returns that same sentence with eachword reversed in place.
First solve it using .each Then utilize the same method using.collect to see the difference.
For example:
- reverse_each_word(“Hello there, and how are you?”)
- #=> “olleH ,ereht dna woh era ?uoy”
Hint: You can’t use an enumerator on astring, so how can we turn our string into an array?
Hint: How can we reverse each word andreturn those altered words? Remember that .each returnsthe original array but other enumerators don’t.
Expert Answer
Answer to RUBY! Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sente…
OR