DEV Community

Discussion on: Daily Challenge #95 - CamelCase Method

Collapse
 
ynndvn profile image
La blatte

Here comes a naive oneliner:

camel=s=>s.split` `.map(e=>e[0].toUpperCase()+e.slice(1).toLowerCase()).join``
Enter fullscreen mode Exit fullscreen mode

For every word, it uppercases its first letter and lowercases the following ones

Collapse
 
balajik profile image
Balaji K

Nice one liner :). But if s is an empty string, then str[0] will be undefined and toUpperCase will throw an error.

Collapse
 
jacobmgevans profile image
Jacob Evans

It's not about finding edge cases. This is a great solution for a coding challenge... Most coding challenges are things you'd put in production anyways