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
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));
- };
const Test = require("@codewars/test-compat"); describe("Solution", function() { it("should test for something", function() { Test.assertEquals(abbrev("internationalization"), "i18n"); Test.assertEquals(abbrev("Localization"), "L10n"); Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a"); Test.assertEquals(abbrev("I Love India"), "I L2e I3a"); }); });
- const Test = require("@codewars/test-compat");
- describe("Solution", function() {
- it("should test for something", function() {
- Test.assertEquals(abbrev("internationalization"), "i18n");
- Test.assertEquals(abbrev("Localization"), "L10n");
- Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a");
- Test.assertEquals(abbrev("I Love India"), "I L2e I3a");
- });
- });
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
}
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(abbrev("internationalization"), "i18n");
Test.assertEquals(abbrev("Localization"), "L10n");
Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a");
});
});