Created
September 12, 2022 21:10
-
-
Save michael-lynch/ee93f4e26f34c8aa7a0975aea2e1c706 to your computer and use it in GitHub Desktop.
Capitalize each word in string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const capitalize = sentence => { | |
const words = sentence.split(' '); | |
for (let i = 0; i < words.length; i++) { | |
if (words[i]) { | |
words[i] = words[i][0].toUpperCase() + words[i].substr(1).toLowerCase(); | |
} | |
} | |
return words.join(' '); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment