Skip to content

Instantly share code, notes, and snippets.

@fuzzygroup
Created March 21, 2018 14:38
Show Gist options
  • Save fuzzygroup/b0f1d09be1e5756383b701017272e68f to your computer and use it in GitHub Desktop.
Save fuzzygroup/b0f1d09be1e5756383b701017272e68f to your computer and use it in GitHub Desktop.
reverse a string with recursion in Ruby
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