Skip to content

Instantly share code, notes, and snippets.

@tonywok
Created April 7, 2017 17:41
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 tonywok/8b6db8f154d643af7fc0bd951bc3560a to your computer and use it in GitHub Desktop.
Save tonywok/8b6db8f154d643af7fc0bd951bc3560a to your computer and use it in GitHub Desktop.
acronym.exs
module Acronym
def abbreviate(string) do
string
|> String.codepoints
|> Enum.with_index
|> Enum.reduce("", fn({letter, idx}, acronym) ->
cond do
String.upcase(letter) == letter and String.downcase(letter) != letter ->
acronym <> letter
String.at(string, idx-1) == " " ->
acronym <> String.upcase(letter)
true ->
acronym
end
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment