Skip to content

Instantly share code, notes, and snippets.

Last active January 23, 2021 10:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Dave Thomas Programming Elixir Exercise: ListsAndRecursion-2 without Kernel.max
defmodule MyList do
def max([]), do: nil
def max([head | tail]), do: findmax(head, head, tail)
defp findmax(current, _next, [head | tail]) do
if head > current, do: findmax(head, current, tail), else: findmax(current, current, tail)
defp findmax(current, next, []) do
if current > next, do: current, else: next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment