DEV Community

Discussion on: JS Coding Question #8: Capitalize All Words In A Sentence [Not So Easy]😓😣

Collapse
 
sbaggott profile image
Sage Baggott

Love these JS coding questions!

A note on solution #2: instead of putting the whitespace between the prev and current props in the template string (Note: ⬜️ = whitespace so it's easier to see):

${prev}⬜️${current[0].toUpperCase() + current.slice(1)}, '')

...you should put the whitespace at the end of the template string:

${prev}${current[0].toUpperCase() + current.slice(1)}⬜️, '')

...that way you won't get an empty space before the first word.