Created
April 7, 2016 17:33
-
-
Save raderj89/df6ce3905bd0a90e3f6c1cf464c4e5f7 to your computer and use it in GitHub Desktop.
write a sum function without an accumulator
This file contains hidden or 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
# Write a sum function without an accumulator | |
defmodule MyList do | |
def sum([]), do: 0 | |
def sum([x]), do: x | |
def sum([ head | tail ]), do: head + sum(tail) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment