SHARE
TWEET

Untitled

a guest May 23rd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top