Last active
March 13, 2018 09:30
-
-
Save agm1984/a6d157d100537a1d503d92ab30ec5f36 to your computer and use it in GitHub Desktop.
Word Capitalizer Function && Sentence Capitalizer Function
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
// CAPITALIZE WORD | |
// ie: Capitalize the first letter | |
const word = 'capitalized' | |
const capitalize = word => [word] | |
.map(letter => letter.slice(0,1).toUpperCase() + letter.slice(1)) | |
.toString() | |
console.log( | |
'Look mom:', | |
capitalize(word) | |
) | |
// CAPITALIZE SENTENCE | |
// ie: Capitalize the first letter of each word | |
const title = `i like to eat cabbage, except when i don't` | |
const toTitleCase = sentence => sentence | |
.split(' ') | |
.map(word => capitalize(word)) | |
.join(' ') | |
console.log( | |
'\nHard mode:', | |
toTitleCase(title) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment