December 21 - Reversing the Words in a String
In today's coding exercise the task is to reverse the words in a string, where words are separated by one or more spaces.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Build a program that reverses the words in a string, where words are separated by one or more spaces.

Exercise Description

Given the following strings:

"dog lazy the over jumped fox brown quick The"

Write a program that reverses the order of the words.

Sample Input

"dog lazy the over jumped fox brown quick The"

Sample Output

"The quick brown fox jumped over the lazy dog"

Real World Usage

This is a very common Ruby coding interview question since it tests knowledge of how to works with strings, arrays, and how they can work together.

Test Cases

Code File