DEV Community

loading...

Discussion on: JavaScript Katas: Abbreviate a two word name

Collapse
mrcodedev profile image
MrCodeDev • Edited

Improved version:

const abbreviateName = (nameToAbbreviate) => {
  const letters = /^[A-Za-z]+$/;
  return nameToAbbreviate
    .split(" ")
    .map((partOfName) => (partOfName[0] !== "" ? partOfName.toUpperCase() : ""))
    .filter((name) => name.match(letters))
    .join(".");
};
Enter fullscreen mode Exit fullscreen mode