Skip to content

Instantly share code, notes, and snippets.

@yowchun93
Created May 13, 2019 01:30
Show Gist options
  • Save yowchun93/db38305511ebc035e181d3ca2165d5ee to your computer and use it in GitHub Desktop.
Save yowchun93/db38305511ebc035e181d3ca2165d5ee to your computer and use it in GitHub Desktop.
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