Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 559 Bytes

reversing_words_in_a_string.md

File metadata and controls

23 lines (17 loc) · 559 Bytes

Description

You need to write a function that reverses the words in a given string. A word can also fit an empty string. If this is not clear enough, here are some examples:

As the input may have trailing spaces, you will also need to ignore unneccesary whitespace.

Example (Input --> Output)

"Hello World" --> "World Hello"
"Hi There." --> "There. Hi"

Happy coding!

My Solution

def reverse(string)
  string.split.reverse.join(' ')
end