Created
June 6, 2019 18:46
-
-
Save pasikonik/f7e352eceb0d69096660849bc23da1e2 to your computer and use it in GitHub Desktop.
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
defmodule People do | |
def list(people) do | |
if Kernel.length(people) == 1 do | |
Enum.at(people, 0)[:name] | |
else | |
Enum.map(people, fn person -> person[:name] end) | |
|> Enum.join(", ") | |
|> String.replace(~r/,([^,]+)$/, " &\\1") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment