Created
February 6, 2016 04:29
-
-
Save jmsevold/862d14158630f273999f to your computer and use it in GitHub Desktop.
Recursively sum the numbers in a list
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
defmodule ListSum do | |
def sum(list) do | |
sum(list,0) | |
end | |
defp sum([h|t],total) do | |
sum(t, total + h) | |
end | |
defp sum([],total) do | |
total | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment