Created
December 25, 2022 20:04
-
-
Save vKxni/40ddba027907e88dae9a15d13bf9560c to your computer and use it in GitHub Desktop.
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 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