Created
June 22, 2016 10:41
-
-
Save tomcha/1eab1a532f2a64057fcd450d82eb74ee to your computer and use it in GitHub Desktop.
recursion2.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
list = [1, 2, 3, 4, 5, 6, 7] | |
def length(list) | |
if list.size == 0 | |
0 | |
else | |
list.shift | |
1 + length(list) | |
end | |
end | |
puts length(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment