Skip to content

Instantly share code, notes, and snippets.

@fschuindt
Last active July 9, 2016 01:08
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 fschuindt/09514c982cb427058331b62009eed45f to your computer and use it in GitHub Desktop.
Save fschuindt/09514c982cb427058331b62009eed45f to your computer and use it in GitHub Desktop.
defmodule Math do
def sum_list(list, accumulator \\ 0)
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