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'