Skip to content

Instantly share code, notes, and snippets.

@bromne
Created February 11, 2019 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bromne/edfb312627f2d8c31ddbce9514c172c3 to your computer and use it in GitHub Desktop.
Save bromne/edfb312627f2d8c31ddbce9514c172c3 to your computer and use it in GitHub Desktop.
const VWL = new Set(["A", "E", "I", "O", "U"]);
function abbr(name) {
if (name.length < 3)
return null;
const NAM = name.toUpperCase();
const HEA = NAM[0];
const TAI = Array.from(NAM.substr(1));
const FLT = TAI.filter(CHR => !VWL.has(CHR)).join("");
if (FLT.length >= 2)
return HEA + FLT.substr(0, 2);
else
return NAM.substr(0, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment