Wednesday, October 5, 2022
HomeC ProgrammingProgramming Challange and Resolution

Programming Challange and Resolution


Let’s contemplate a phrase too lengthy, if its size is strictly greater than 10 characters. All too lengthy phrases must be changed with a particular abbreviation.

Thus, “localization” will likely be spelt as “l10n”, and “internationalization» will likely be spelt as “i18n”. Phrases with size lower than 10 ought to print the identical.

inputCopy

4

phrase

localization

internationalization

pneumonoultramicroscopicsilicovolcanoconiosis

outputCopy

phrase

l10n

i18n

p43s

Resolution:

const strAbbr = str =>{

  let startWord = str[0];

  let endWord = str[str.length – 1];

  if(str.size<=10){

    return str;

  }

  else{

    return `${startWord}${str.length-2}${endWord}`;

  }

}

console.log(strAbbr(‘iamstringo’))

console.log(strAbbr(‘iaminlengthmorethanten’))

console.log(strAbbr(‘lesslength’))

OUTPUT

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments