DEV Community

Cover image for Solving 1 random codewars challenge in Typescript per day - Day 1
Iván Roldán Lusich
Iván Roldán Lusich

Posted on

5

Solving 1 random codewars challenge in Typescript per day - Day 1

Today's challenge (direct link):

Write simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. All words must have their first letter capitalized without spaces.

For instance:

camelCase("hello case"); // => "HelloCase"
camelCase("camel case word"); // => "CamelCaseWord"
Enter fullscreen mode Exit fullscreen mode

My Solution:

export function camelCase(str: string): string {
  const splitStr = str.split(' ');

  return splitStr.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
}
Enter fullscreen mode Exit fullscreen mode

Well, this was a really simple one. Just split the original string at every space and then map over that array capitalizing every word.

Hopefully, we'll get a harder one next time. Have a nice day!

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay