1function titleCase(str) {
2 return str
3 .split(' ')
4 .map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase())
5 .join(' ');
6}
7console.log(titleCase("I'm a little tea pot")); // I'm A Little tea Pot
8
1function titleCase(sentence) {
2 let sentence = string.toLowerCase().split(" ");
3 for (let i = 0; i < sentence.length; i++) {
4 sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
5 }
6
7 return sentence.join(" ");
8}
9
1function toTitles(s){ return s.replace(/\w\S*/g, function(t) { return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase(); }); }
2var str = toTitles('abraham lincoln'); // Abraham Lincoln