Created
June 22, 2016 10:40
-
-
Save tomcha/b2860384c2ce1a054c9809682d60f39a to your computer and use it in GitHub Desktop.
Recursion1
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] | |
def sum(nums) | |
if nums.size == 0 | |
0 | |
else | |
n = nums.shift | |
n + sum(nums) | |
end | |
end | |
puts sum(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment