Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

RUBY! Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in

RUBY!

\Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place.

First solve it using .each Then utilize the same method using .collect to see the difference.

For example:

  1. reverse_each_word("Hello there, and how are you?")
  2. #=> "olleH ,ereht dna woh era ?uoy"

Hint: You can't use an enumerator on a string, so how can we turn our string into an array?

Hint: How can we reverse each word and return those altered words? Remember that .each returns the original array but other enumerators don't.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago