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

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)