Challenge #16: Normalizing Names

For this challenge, we’re getting a list of names, and need to abbreviate all first names.

Any leading first names - recognized if starting with an upper case letter - should be abbreviated to an initial. The last word is always understood to be the last name.

For example:

  • Sherlock Holmes -> S. Holmes
  • Ernst Theodor Amadeus Hoffmann -> E. T. A. Hoffmann
  • Ludwig van Beethoven -> L. van Beethoven

Use this start.dfl (9.8 KB) flow to get started.

We’re looking to arrive at a result like this:

Name Short Name
Sherlock Holmes S. Holmes
John Watson J. Watson
Charles Augustus Magnussen C. A. Magnussen
Greg Lestrade G. Lestrade
Enoch J. Drebber E. J. Drebber
Wilhelm Gottsreich Sigismond von Ormstein W. G. S. von Ormstein
Bill Wiggins B. Wiggins
Edward Dunn Malone E. D. Malone
Culverton Smith C. Smith

Here’s a solution_name_normalization.dfl (25.3 KB) using built-in functions:

The idea is to:

  • split the given string by whitespace
  • treat the last element as the last name
  • map leading words through a function that decides whether to abbreviate the word or leave it as is
  • join mapped leading words and last name back together