Skip to content

Instantly share code, notes, and snippets.

@agm1984
Last active March 13, 2018 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agm1984/a6d157d100537a1d503d92ab30ec5f36 to your computer and use it in GitHub Desktop.
Save agm1984/a6d157d100537a1d503d92ab30ec5f36 to your computer and use it in GitHub Desktop.
Word Capitalizer Function && Sentence Capitalizer Function
// 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