Skip to content

Instantly share code, notes, and snippets.

Created Sep 13, 2015
What would you like to do?
Javascript RLE
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