Ad

You have to create an abbreviation function. It will take string and return a string while taking the first and last char of word and replace the remaining with the number of chars in it.

For example:
internationalization => i18n
Localization => L10n
Deepak-Vishwa => D4k-V4a
I Love India => I L2e I3a

Code
Diff
  • const abbrevWord = (text = "") => {
      if (text.length < 3) return text;
      const first = text.charAt(0);
      const last = text.slice(-1);
      const remLen = text.length - 2;
      return `${first}${remLen}${last}`;
    };
    const simpleChars = /\w+/g;
    const abbrev = (text = "") => {
      return text.replace(simpleChars, (matched) => abbrevWord(matched));
    };
    
    • function abbrev(str) {
    • // TODO
    • }
    • const abbrevWord = (text = "") => {
    • if (text.length < 3) return text;
    • const first = text.charAt(0);
    • const last = text.slice(-1);
    • const remLen = text.length - 2;
    • return `${first}${remLen}${last}`;
    • };
    • const simpleChars = /\w+/g;
    • const abbrev = (text = "") => {
    • return text.replace(simpleChars, (matched) => abbrevWord(matched));
    • };

You have to create an which abbreviation function. It will take string and return a string while taking the first and last char and replace the remaining with the number of chars.

For example:
internationalization => i18n
Localization => L10n
Deepak-Vishwa => D4k-V4a

function abbrev(str) {
  // TODO
  
}