function toTitleCase(str) {
return str.replace(/wS*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
//Updated
//capitalize only the first letter of the string.
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string.
function capitalizeWords(string) {
return string.replace(/(?:^|s)S/g, function(a) { return a.toUpperCase(); });
};
const str = "HERE'S AN UPPERCASE PART of the string";
const upperCaseWords = str.match(/([A-Z][A-Z]+|[A-Z])/g);
console.log(upperCaseWords);
const capitalizeFirstLetter(string) =>
string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
const mySentence = "freeCodeCamp is an awesome resource";
const finalSentence = mySentence.replace(/(^w{1})|(s+w{1})/g, letter => letter.toUpperCase())
console.log(finalSentence)