DEV Community

Discussion on: Capitalize the first letter of every word

Collapse
 
willsmart profile image
willsmart

Hey thanks for that, that's awesome!

One nice thing about the regex way is that it targets the letters it needs to capitalize. I added test cases for an already capitalized sentence and toTitleCase gets a 400% speedup compared to the non-capitalized sentence (since it won't call toUpperCase if it doesn't need to). The others didn't get any speed up (their code could be tweaked, but I don't think there's a way to get such a boost).
Benchmark here