Created
May 26, 2015 09:01
-
-
Save shiwork/af7ec21e475383050291 to your computer and use it in GitHub Desktop.
elixir
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
defmodule Math do | |
def sum_list([head|tail]) do | |
sum_list(tail, head) | |
end | |
def sum_list([head|tail], accumulator) do | |
sum_list(tail, head + accumulator) | |
end | |
def sum_list([], accumulator) do | |
accumulator | |
end | |
end | |
IO.puts Math.sum_list([1, 2, 3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment