Created
May 13, 2019 01:30
-
-
Save yowchun93/db38305511ebc035e181d3ca2165d5ee 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 CamelCase do | |
def to_camel_case(word) do | |
words = String.codepoints(word) | |
convert("-", words) |> Enum.join("") | |
end | |
def convert(a, []) do | |
[] | |
end | |
def convert(a, [ a | [h|t] ]) do | |
[String.upcase(h) | convert(a, t)] | |
end | |
def convert(a, [h|t]) do | |
[h | convert(a, t)] | |
end | |
end | |
CamelCase.to_camel_case("the-stealth-warrior") |> IO.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment