d
Amit DhamuSoftware Engineer
 

Generate Initials From String

1 minute read 00000 views
const initials = string =>
  string
    .split(' ')
    .map(s => s.charAt(0))
    .join('')
> initials('John Smith');
'JS'
> initials('John James Smith');
'JJS'
> initials('John James-Smith');
'JJ'
> initials('JohnJames-Smith');
'J'
> initials('james has lots of names');
'jhlon'