diff --git a/DSA/Strings/Capitalize.js b/DSA/Strings/Capitalize.js index 86968fc..0333a33 100644 --- a/DSA/Strings/Capitalize.js +++ b/DSA/Strings/Capitalize.js @@ -1,16 +1,16 @@ // Convert a sentence to title case using Javascript // example: Input: this is a phrase // Output: This Is A Phrase - -const toTitleCase = (sentence) =>{ + +const toTitleCase = (sentence) => { let words = sentence.split(' '); - let capitalizedSentence=''; - words.forEach((word)=>{ + let capitalizedSentence = ''; + words.forEach((word) => { capitalizedSentence += String(word).charAt(0).toUpperCase() + word.slice(1) + ' '; }) - + return capitalizedSentence.trim(); } -const sentence = 'this is a phrase' +const sentence = 'this is a sentence' console.log(toTitleCase(sentence)); \ No newline at end of file