Last active
June 3, 2019 04:48
-
-
Save kellyfelkins/6db08be6a6a01f82897f710633a7bed1 to your computer and use it in GitHub Desktop.
find first singleton 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
def first_singleton(list) do | |
list | |
|> Enum.sort() | |
|> no_partner?() | |
end | |
def no_partner?([value | remaining_values]) do | |
if value == hd(remaining_values) do | |
Enum.reject(remaining_values, &(&1 == value)) | |
|> no_partner?() | |
else | |
value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment