Created
June 2, 2017 10:28
-
-
Save srph/07250ef5410af5722fd1bf8098b0cc5a to your computer and use it in GitHub Desktop.
JS: rle
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 rle(input) { | |
| let result = '' | |
| while (input.length) { | |
| const capture = new RegExp(`${input[0]}+`) | |
| const captured = capture.exec(input)[0] | |
| result += `${captured.length}${captured[0]}` | |
| input = input.substr(captured.length) | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment