Created
September 13, 2015 23:30
-
-
Save simoneb/ce45daa8f5b42b5c88cb to your computer and use it in GitHub Desktop.
Javascript RLE
This file contains 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 str = 'AAABCCDEEE'; | |
var expected = '3A1B2C1D3E'; | |
var result = _.reduce(str+'\0',(a,c,i,s)=>{if(i&&s[i-1]!== c){a.r+=a.c+s[i-1];a.c=1;}else{a.c++;}return a;},{c:0,r:''}).r | |
result === expected; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment