Skip to content

Instantly share code, notes, and snippets.

@eibrahim
Created February 2, 2016 21:33
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 eibrahim/1abddbf197a93796dc33 to your computer and use it in GitHub Desktop.
Save eibrahim/1abddbf197a93796dc33 to your computer and use it in GitHub Desktop.
Find the smallest element in a list
def min [] do 0 end
def min [h|t] do _min [h|t],h end
defp _min [],smallest do smallest end
defp _min [h|t], smallest do
cond do
smallest <= h ->
_min t, smallest
smallest >= h ->
_min t, h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment