Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". Words with length less than 10 should print the same.
inputCopy
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
outputCopy
word
l10n
i18n
p43s
Solution:
const strAbbr = str =>{
  let startWord = str[0];
  let endWord = str[str.length - 1];
  if(str.length<=10){
    return str;
  }
  else{
    return `${startWord}${str.length-2}${endWord}`;
  }
}
console.log(strAbbr('iamstringo'))
console.log(strAbbr('iaminlengthmorethanten'))
console.log(strAbbr('lesslength'))
OUTPUT

Comments
Post a Comment