Skip to content

Instantly share code, notes, and snippets.

@marufsiddiqui
Created May 11, 2017 02:11
Show Gist options
  • Save marufsiddiqui/7bf1355674ca8b57161bccb5e1600a72 to your computer and use it in GitHub Desktop.
Save marufsiddiqui/7bf1355674ca8b57161bccb5e1600a72 to your computer and use it in GitHub Desktop.
function rlEncode(str) {
var strs = str.split('');
var a1 = strs.reduce((acc, i) => {
if (i === acc.cur) {
return {
cur: i,
count: acc.count+1,
s: acc.s
}
} else {
return {
cur: i,
count: 1,
s: acc.s + acc.cur + acc.count
}
}
}, {cur: strs[0], count: 0, s: ''});
return a1.s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment