exercism/elixir/acronym/lib/acronym.ex

15 lines
324 B
Elixir
Raw Normal View History

2024-03-11 15:44:09 +00:00
defmodule Acronym do
@doc """
Generate an acronym from a string.
"This is a string" => "TIAS"
"""
@spec abbreviate(String.t()) :: String.t()
def abbreviate(string) do
string
|> String.split([" ", "-", "_"], trim: true)
|> Enum.map(&String.first/1)
|> Enum.join()
|> String.upcase()
end
end