Last active
June 29, 2017 14:08
-
-
Save sekmo/3e41150231d0a5a4b918447814414dbc to your computer and use it in GitHub Desktop.
Reverse a string in recursive fashion - Ruby
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
def reverse(string) | |
if string.size > 1 | |
string[-1] + reverse(string[0..-2]) | |
else | |
string | |
end | |
end | |
puts reverse "Francesco" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment