Capitalize First Letter of Each Word
EasyP3Coding
Implement capitalizeWords(str), which upper-cases the first letter of every word and lower-cases the rest of that word.
A word is a maximal run of non-space characters; words are separated by one or more space characters (" "). Keep the original spacing exactly, including leading, trailing and repeated spaces. Characters that are not letters stay as they are, so "3rd" stays "3rd" and "o'neil" becomes "O'neil".
Example 1
- Input
- capitalizeWords('hello wORLD')
- Output
- 'Hello World'
Constraints
- 0 <= str.length <= 10^5
- Only the space character separates words.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 7. ⌘Enter runs, ⌘⇧Enter submits.