Skip to content

Instantly share code, notes, and snippets.

@sekmo
Last active June 29, 2017 14:08
Show Gist options
  • Save sekmo/3e41150231d0a5a4b918447814414dbc to your computer and use it in GitHub Desktop.
Save sekmo/3e41150231d0a5a4b918447814414dbc to your computer and use it in GitHub Desktop.
Reverse a string in recursive fashion - Ruby
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