Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created June 22, 2016 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomcha/1eab1a532f2a64057fcd450d82eb74ee to your computer and use it in GitHub Desktop.
Save tomcha/1eab1a532f2a64057fcd450d82eb74ee to your computer and use it in GitHub Desktop.
recursion2.rb
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