Skip to content

Instantly share code, notes, and snippets.

@eliorivero
Created February 5, 2020 21:22
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 eliorivero/c6bb310ad6bc47654e211909a6dadddd to your computer and use it in GitHub Desktop.
Save eliorivero/c6bb310ad6bc47654e211909a6dadddd to your computer and use it in GitHub Desktop.
Get word initials
/**
* Given a string of words separated by spaces, return the first letter of the first two words.
* Originally intended to get the initials of a "name lastName" string.
*
* @param {string} words A list of words. Only the first two are taken into account the rest are ignored.
*
* @returns {string}
*/
const getNameInitials = words => name.split(' ').slice(0, 2).reduce( (acc, cur) => acc + cur[0], '' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment