Created
March 21, 2018 14:38
-
-
Save fuzzygroup/b0f1d09be1e5756383b701017272e68f to your computer and use it in GitHub Desktop.
reverse a string with recursion in Ruby
This file contains 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_recursive(string) | |
return string if string.size <= 1 | |
tail = string[-1] | |
head = string[0...-1] | |
rest = reverse_recursive(head) | |
tail + rest | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment