/* the first letter of each word will have a regular size */.mnspan::first-letter{font-size:1rem;}/* the words in the middle (not first or last) will have a font-size of 0 */.mnspan:not(:first-child):not(:last-child){font-size:0;display:inline-block;}/* add a . at the end of each shortened word */.mnspan:not(:first-child):not(:last-child)::after{content:".";font-size:1rem;}
Wrap each word in a span, and add the class "mn" to the container.
Live demo on CodePen.
definitializeName(name:str):name=name.split(" ")if(len(name)>=3):#loop from first name to last name.
foriinrange(1,len(name)-1):name[i]=name[i][0]+"."name=' '.join(name)returnname
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)
constinitialiseMiddleNames=(fullName)=>{constnames=fullName.split('')if(names.length<=2)returnfullNameconstfirstName=names.shift()constlastName=names.pop()constinitials=names.map(name=>name.charAt(0))return`${firstName}${initials.join('. ')}. ${lastName}`}initialiseMiddleNames('Jack Ryan')// Jack RyaninitialiseMiddleNames('Lois Mary Lane')// Lois M. LaneinitialiseMiddleNames('Dimitri')// DimitriinitialiseMiddleNames('Alice Betty Catherine Davis')// Alice B. C. Davis
constinitializeMiddleNames=(name)=>{constnameArr=name.split('')for(letindex=1;index<nameArr.length-1;index++){nameArr[index]=`${nameArr[index].substring(0,1)}.`;}returnnameArr.join('')}initializeMiddleNames('Jack Ryan')// Jack RyaninitializeMiddleNames('Lois Mary Lane')// Lois M. LaneinitializeMiddleNames('Dimitri')// DimitriinitializeMiddleNames('Alice Betty Catherine Davis')// Alice B. C. Davis
Game Developer, Metaverse Creater.
With over four years of experience working in the metaverse, Theo's had the opportunity to work on top experiences, spearheading technical and creative design.
I had two attempts at this, my first was only for full names up to three words but after realising I needed to expand the program to work on more I rewrote the program. Both and posted below and annotated.
First attempt
definitialize(full_name):names=full_name.split()num_names=len(names)ifnum_names==3:Middle_initial=names[1]print(names[0],Middle_initial[0],".",names[2])elifnum_names<=2:print(names[0],names[1])else:print("Compatability for names of 4 or more has not been added.")full_name=input("Full Name: ")ifnotfull_name=="":initialize(full_name)
Game Developer, Metaverse Creater.
With over four years of experience working in the metaverse, Theo's had the opportunity to work on top experiences, spearheading technical and creative design.
Game Developer, Metaverse Creater.
With over four years of experience working in the metaverse, Theo's had the opportunity to work on top experiences, spearheading technical and creative design.
CSS
Wrap each word in a
span, and add the class "mn" to the container.Live demo on CodePen.
I also did a JavaScript version on that same demo:
If you select-and-copy the names, the full name is copied instead of the shortened one.
Ruby solution
I just changed a few things in a similar function from singl.page. Doesn’t use join(). Works when only a single name is provided.
Not the best solution: ))
PHP Solution
JavaScript:
Here's mine, with a more functional approach - also takes into account name strings that have erroneous spaces
jsbin.com/gedejih/edit?js,console
Javascript
This was fun :)
Python.
I had two attempts at this, my first was only for full names up to three words but after realising I needed to expand the program to work on more I rewrote the program. Both and posted below and annotated.
First attempt
Second Attempt
I wasn't too happy on the result,
Any pointers on how to I could improve my code would be great!
But ey it works,
😁..I am uh, very, mature.
Python
Here is the simple solution with Python:
ruby <3
My solution in js
Python :
Nice,
Here's my Python solutions!
dev.to/teotcd/comment/e6fl