Created
May 11, 2017 02:11
-
-
Save marufsiddiqui/7bf1355674ca8b57161bccb5e1600a72 to your computer and use it in GitHub Desktop.
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
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