Skip to content

Instantly share code, notes, and snippets.

@vKxni
Created December 25, 2022 20:04
Show Gist options
  • Save vKxni/40ddba027907e88dae9a15d13bf9560c to your computer and use it in GitHub Desktop.
Save vKxni/40ddba027907e88dae9a15d13bf9560c to your computer and use it in GitHub Desktop.
defmodule String do
def unique_capitalization(string) do
string
|> String.graphemes
|> Enum.with_index
|> Enum.map(fn {grapheme, index} ->
if rem(index, 2) == 1, do: String.capitalize(grapheme), else: grapheme
end)
|> Enum.join
end
end
# 'javascript' => 'jAvAsCrIpT'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment