Last active
February 4, 2023 05:50
-
-
Save cdcooksey/0100bb3bb42ac9501529e4f7afb775f6 to your computer and use it in GitHub Desktop.
recursion.rb
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 countdown(n) | |
return if n.zero? # base case | |
puts n | |
countdown(n-1) # getting closer to base case | |
end | |
countdown(5) # => output: 5 4 3 2 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment