Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. defmodule CamelCase do
  2. def to_camel_case(word) do
  3. words = String.codepoints(word)
  4. convert("-", words) |> Enum.join("")
  5. end
  6.  
  7. def convert(a, []) do
  8. []
  9. end
  10.  
  11. def convert(a, [ a | [h|t] ]) do
  12. [String.upcase(h) | convert(a, t)]
  13. end
  14.  
  15. def convert(a, [h|t]) do
  16. [h | convert(a, t)]
  17. end
  18. end
  19.  
  20. CamelCase.to_camel_case("the-stealth-warrior") |> IO.inspect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement