const mySentence = "freeCodeCamp is an awesome resource"; const finalSentence = mySentence.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase());//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(); }); };text.replace(/(^\w|\s\w)/g, m => m.toUpperCase()); // Explanation: // // ^\w : first character of the string // | : or // \s\w : first character after whitespace // (^\w|\s\w) Capture the pattern. // g Flag: Match all occurrences. // Example usage: // Create a reusable function: const toTitleCase = str => str.replace(/(^\w|\s\w)/g, m => m.toUpperCase()); // Call the function: const myStringInTitleCase = toTitleCase(myString); "thisIsATrickyOne".split(/(?=[A-Z])/); //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 capitalizeFirstLetter(string) => string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()function capitalizeWords(string) { return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); }); };const mySentence = "freeCodeCamp is an awesome resource"; const words = mySentence.split(" "); for (let i = 0; i < words.length; i++) { words[i] = words[i][0].toUpperCase() + words[i].substr(1); } words.join(" ");export function capitalize(str: string, all: boolean = false) { if (all) return str.split(' ').map(s => capitalize(s)).join(' '); return str.charAt(0).toUpperCase() + str.slice(1); }function capitalize(paragraph) { const paragraphCleaned = paragraph.replace(/\s{2,}/, " ") const paragraphSplitted = paragraphCleaned.split(" ") const capitalized = paragraphSplitted.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) return capitalized.join(" ") }js string