Created
April 7, 2017 17:41
Revisions
-
tonywok created this gist
Apr 7, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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