DEV Community

Discussion on: Challenge-- Capitalize each word in a string

Collapse
 
neradev profile image
Moritz Schramm • Edited

Here is my solution in JavaScript :)

const capitalize = (t) => t.replace(/(^|\s)[a-z]/g, (a) => a.toUpperCase());
Collapse
 
wisniewski94 profile image
Wiktor Wiśniewski

I don't know about this one, somehow @jasterix solution was more friendly to me. I'm not a fan of RegEx because it's really hard to memorize and easy to forget when you are not using it for a week or so (exaggerating)

Collapse
 
neradev profile image
Moritz Schramm

Luckily (or sometimes badly), everyone finds something different easier to read. I personally like the RegEx approach more, since it directly show what happens to which parts. I am quite used to read RegEx and find it more confusing to think again about what function is doing what and resulting in what.

Collapse
 
jasterix profile image
Jasterix • Edited

Very nice! Unfortunately I suck at RegEx :(

Would the Big-O of this be constant?

Collapse
 
neradev profile image
Moritz Schramm • Edited

This one should be O(n). I had the same question in mind and googled it. Never the less, I am actually a big fan of regex :D I have fun writing them.