I build software and work with software teams to improve workflows, communication, and best practices. If you'd like to work together, please get in touch!
functionformatName(name){/* Trim out any spaces at the beginning or end,
* split the name into segments,
* and filter out empty strings. */constsplitName=name.trim().split('').filter(n=>n.length>0)returnsplitName.map((namePart,index)=>{/* Return the first and last names as they are */if(index===0||index===splitName.length-1)returnnamePart/* Otherwise, get the first character,
* make sure it is capitalized,
* and return it with a `.` */return`${namePart[0].toUpperCase()}.`}).join('')}constformattedNames=names.map(formatName)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's mine, with a more functional approach - also takes into account name strings that have erroneous spaces
jsbin.com/gedejih/edit?js,console