Your challenge today is to initialize an individual's middle name (if there is any).
Example:
'Jack Ryan' => 'Jack Ryan'
'Lois Mary Lane' => 'Lois M. Lane'
'Dimitri' => 'Dimitri'
'Alice Betty Catherine Davis' => 'Alice B. C. Davis'
Good luck!
This challenge comes from manonacodingmission on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (20)
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.
Not the best solution: ))
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.
PHP Solution
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
JavaScript:
Here is the simple solution with Python:
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.
My solution in js
ruby <3