Skip to content

Instantly share code, notes, and snippets.

@inodaf
Created April 12, 2020 20:52
Show Gist options
  • Save inodaf/1785fe55f9b01bfda686914d2cb5a40f to your computer and use it in GitHub Desktop.
Save inodaf/1785fe55f9b01bfda686914d2cb5a40f to your computer and use it in GitHub Desktop.
Getting Name Capitals in JavaScript
const splitWords = phrase => phrase.split(' ')
const firstLetter = word => word.charAt(0)
const lastLetter = word => word.charAt(word.length - 1)
const initialLetter = words => words
.map(word => word.charAt(0))
.join('')
const firstAndLastLetter = word => [
firstLetter(word),
lastLetter(word)
].join('')
const getNameCapitals = name => firstAndLastLetter(
initialLetter(
splitWords(name)
)
)
getNameCapitals('Isac Fadoni Leite') // IL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment