Developers often shorten long words by keeping the first and last letter and replacing everything between them with the number of characters removed, which is how internationalization becomes i18n.
Given a sentence whose words are separated by single spaces, abbreviate every word that is longer than 4 characters using that rule, and leave every word of 4 characters or fewer untouched. Return the words rejoined with single spaces. If the sentence is null, empty, or made up only of whitespace, return an empty string.
Examples:
Input: sentence = 'the internationalization of localization'
Output: 'the i18n of l10n'
Explanation: 'internationalization' has 20 letters so 18 are replaced, and 'localization' has 12 so 10 are replaced
Input: sentence = 'hello world'
Output: 'h3o w3d'
Explanation: Both words have 5 letters, so 3 characters are replaced in each
Input: sentence = 'a bc def ghij'
Output: 'a bc def ghij'
Explanation: Every word is 4 characters or fewer, so nothing changes
Input: sentence = ''
Output: ''
Explanation: An empty sentence returns an empty string
Input: sentence = null
Output: ''
Explanation: Null input returns an empty string
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
Contest runs November 16 - 30. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.