The word i18n is a common abbreviation of internationalization in the developer community, used instead of typing the whole word and trying to spell it correctly. Similarly, a11y is an abbreviation of accessibility.
Write a function that takes a string and turns any and all "words" (see below) within that string of length 4 or greater into an abbreviation, following these rules:
A "word" is a sequence of alphabetical characters. By this definition, any other character like a space or hyphen (eg. "elephant-ride") will split up a series of letters into two words (eg. "elephant" and "ride").
The abbreviated version of the word should have the first letter, then the number of removed characters, then the last letter (eg. "elephant ride" => "e6t r2e").
Example
abbreviate("elephant-rides are really fun!")
// ^^^^^^^^*^^^^^*^^^*^^^^^^*^^^*
// words (^): "elephant" "rides" "are" "really" "fun"
// 123456 123 1 1234 1
// ignore short words: X X
// abbreviate: "e6t" "r3s" "are" "r4y" "fun"
// all non-word characters (*) remain in place
// "-" " " " " " " "!"
=== "e6t-r3s are r4y fun!"
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #56 Maximum subarray sum (5kyu) (0) | 2018.06.05 |
---|---|
codewars #55 Sum of Two Integers (6kyu) (0) | 2018.06.04 |
codewars #53 FIXME: Hello (6kyu) (0) | 2018.05.31 |
codewars #52 Are they the "same"? (6kyu) (0) | 2018.05.30 |
codewars #51 Simple string indices (6kyu) (0) | 2018.05.29 |