Skip to content

Instantly share code, notes, and snippets.

@raderj89
Created April 7, 2016 17:33
Show Gist options
  • Save raderj89/df6ce3905bd0a90e3f6c1cf464c4e5f7 to your computer and use it in GitHub Desktop.
Save raderj89/df6ce3905bd0a90e3f6c1cf464c4e5f7 to your computer and use it in GitHub Desktop.
write a sum function without an accumulator
# 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