Last active
May 29, 2017 11:21
-
-
Save hhimanshu/311232844dc3a4c764e3 to your computer and use it in GitHub Desktop.
Erlang: Find Minimum and Maximum in 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
-module(recursive). | |
-export([minimum/1, maximum/1]). | |
minimum([]) -> io:format("can not find minimum of empty list~n"); | |
minimum([H|T]) -> | |
minimum(H, T). | |
minimum(Min, [H|T]) -> | |
case Min < H of | |
true -> minimum(Min, T); | |
false -> minimum(H, T) | |
end; | |
minimum(Min, []) -> Min. | |
maximum([]) -> io:format("can not find max from empty list~n"); | |
maximum([H|T]) -> | |
maximum(H, T). | |
maximum(Max, [H|T]) -> | |
case Max > H of | |
true -> maximum(Max, T); | |
false -> maximum(H, T) | |
end; | |
maximum(Max, []) -> Max. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm new to Erlang, and wrote this function a bit in a different way, could you comment on which would be more
erlang
-y ?