Skip to content

Instantly share code, notes, and snippets.

@jmsevold
Created February 6, 2016 04:29
Show Gist options
  • Save jmsevold/862d14158630f273999f to your computer and use it in GitHub Desktop.
Save jmsevold/862d14158630f273999f to your computer and use it in GitHub Desktop.
Recursively sum the numbers in a list
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