DEV Community

Discussion on: How to Titleize a Sentence in JavaScript

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

You method for splitting words is probably overly simplistic - the function will produce incorrect results with some combinations of punctuation. Maybe consider using regex to split on non-word characters. The function will also wreck words that are intentionally in all caps - UK, USA, NATO etc.

Collapse
 
ratracegrad profile image
Jennifer Bland

You are correct but remember the requirements in which I am working. We just need to proper capitalize subjects of email messages that would not have all cap words like you mentioned.

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Another example email subject that will not be handled correctly by the code:

Please proofread my review of 'Midnight in the Garden of Good and Evil'
Enter fullscreen mode Exit fullscreen mode