3 ms·
> Maybe we need to zoom out of ancient languages... Maybe. Compare your function to the equivalent Erlang one: sum(L) -> sum(L, 0). sum([], Acc) ->
by simoncion 11y ago
> Maybe we need to zoom out of ancient languages...
Maybe. Compare your function to the equivalent Erlang one:
sum(L) ->
sum(L, 0).
sum([], Acc) ->
Acc;
sum([Num|Rest], Acc) ->
sum(Rest, Acc+Num).
Assuming that it's in a module called 'math', run it like so:
math:sum([5,4,3,2,1]).
15