Skip to content

Instantly share code, notes, and snippets.

@simoneb
Created September 13, 2015 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simoneb/ce45daa8f5b42b5c88cb to your computer and use it in GitHub Desktop.
Save simoneb/ce45daa8f5b42b5c88cb to your computer and use it in GitHub Desktop.
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