Skip to content

Instantly share code, notes, and snippets.

@schainks
Last active March 23, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schainks/8d87f605de2030f797c4 to your computer and use it in GitHub Desktop.
Save schainks/8d87f605de2030f797c4 to your computer and use it in GitHub Desktop.
abbreviate strings in elixir
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