Created
February 2, 2016 21:33
-
-
Save eibrahim/1abddbf197a93796dc33 to your computer and use it in GitHub Desktop.
Find the smallest element in a list
This file contains 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
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