Created
July 31, 2013 07:36
-
-
Save chiragmongia/6120069 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Question- Reverse Sentence | |
| #Use string methods to reverse the words arrangement in a sentence. | |
| #Eg: "An apple a day keeps the doctor away" -> "away doctor the keeps day a apple An" | |
| def reverse_string (input_string) | |
| input_string.split.reverse!.join(" ") | |
| end | |
| #Main | |
| p "Enter the string" | |
| input_string = gets.chomp | |
| puts "---String Reversed---" | |
| puts reverse_string (input_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment