Created
August 23, 2013 12:01
-
-
Save rin/6318576 to your computer and use it in GitHub Desktop.
Programming Elixir, Chapter 7.6, Exercise ListsAndRecursion-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyList do | |
def max([]), do: nil | |
def max([head | []]), do: head | |
def max([head | tail]) do | |
_max(head, max(tail)) | |
end | |
defp _max(a, b), do: (if a > b, do: a, else: b) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment