Last active
April 1, 2016 19:12
-
-
Save alexwebgr/f1d76c5f7c0cf3103112066b08bd9f6e to your computer and use it in GitHub Desktop.
Concatenate consecutive characters followed by the number of characters if it is over 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = 'aaaabbbbccccpqesrt'; | |
var compressedString = ''; | |
var s = input.match(/([a-zA-Z])\1*/g) || []; | |
s.forEach(function(value) { | |
var k = ''; | |
if(value.length > 1) { | |
k = value.length; | |
} | |
compressedString += value.charAt(0) + k; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment