Last active
March 23, 2016 08:21
-
-
Save schainks/8d87f605de2030f797c4 to your computer and use it in GitHub Desktop.
abbreviate strings in elixir
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 Acronym do | |
def abbrev(string) do | |
string | |
|> String.split(" ") | |
|> Enum.map(fn(x) -> hd(String.codepoints(x)) end) | |
|> Enum.map(fn(x) -> String.upcase(x) end) | |
end | |
def abbrev2(string) do | |
string | |
|> String.split(" ") | |
|> Enum.reduce([], fn(x, acc) -> [x |> String.codepoints() |> hd() | acc] end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment