function toTitleCase(str) {
return str.replace(/wS*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
function capitalizeTheFirstLetterOfEachWord(words) {
var separateWord = words.toLowerCase().split(' ');
for (var i = 0; i < separateWord.length; i++) {
separateWord[i] = separateWord[i].charAt(0).toUpperCase() +
separateWord[i].substring(1);
}
return separateWord.join(' ');
}
console.log(capitalizeTheFirstLetterOfEachWord("my name is john"));
const mySentence = "freeCodeCamp is an awesome resource";
const finalSentence = mySentence.replace(/(^w{1})|(s+w{1})/g, letter => letter.toUpperCase())
console.log(finalSentence)