titleCase

Easy · String Manipulations · 2 test cases

Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.

Examples

titleCase('I'm a little tea pot') → 'I'm A Little Tea Pot'

Starter code

function titleCase(str) {

}

Complexity of the optimal solution

Time O(n), space O(n). The operations `toLowerCase`, `split`, `map`, and `join` all process the entire string or resulting arrays. The time and space required are proportional to the length of the input string (n).

Solve titleCase in the browser