Skip to content

Instantly share code, notes, and snippets.

@pfigue
Created November 15, 2011 20:54
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 pfigue/1368313 to your computer and use it in GitHub Desktop.
Save pfigue/1368313 to your computer and use it in GitHub Desktop.
Return the biggest term in a list
-module(max).
-export([max/1, max0/2]).
max([]) -> [];
max([Head | Tail]) -> max0(Tail, Head).
max0([], CurrentMax) -> CurrentMax;
max0([Head | Tail], CurrentMax) ->
if
CurrentMax >= Head -> max0(Tail, CurrentMax);
true -> max0(Tail, Head)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment