Skip to content

Instantly share code, notes, and snippets.

@namxam
Created September 25, 2015 14:29
Show Gist options
  • Save namxam/bb2c1410c6a8965f530e to your computer and use it in GitHub Desktop.
Save namxam/bb2c1410c6a8965f530e to your computer and use it in GitHub Desktop.
defmodule Exercise1 do
def maximum([head | tail]) do
maximum(tail, head)
end
defp maximum([], largest_score) do
largest_score
end
defp maximum([head | tail], largest_score) when largest_score > head do
maximum(tail, largest_score)
end
defp maximum([head | tail], _largest_score) do
maximum(tail, head)
end
end
[6, 4, 5, 3, 2, 7, 8, 10, 9, 1]
|> Exercise1.maximum
|> IO.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment