DEV Community

Discussion on: Daily Challenge #95 - CamelCase Method

Collapse
 
denolfe profile image
Elliot DeNolf

Crystal

def to_camel(input : String)
  input.split(" ").map(&.capitalize).join
end

Tests

describe "to_camel" do
  it "handles 1 word" do
    to_camel("hello").should eq "Hello"
  end

  it "handles 2 words" do
    to_camel("hello world").should eq "HelloWorld"
  end

  it "handles empty string" do
    to_camel("").should eq ""
  end

  it "handles extra whitespace" do
    to_camel("  hello  world  ").should eq "HelloWorld"
  end
end