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"
My Solution:
export function camelCase(str: string): string {
const splitStr = str.split(' ');
return splitStr.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
}
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)