Skip to content

Instantly share code, notes, and snippets.

@srph
Created June 2, 2017 10:28
Show Gist options
  • Select an option

  • Save srph/07250ef5410af5722fd1bf8098b0cc5a to your computer and use it in GitHub Desktop.

Select an option

Save srph/07250ef5410af5722fd1bf8098b0cc5a to your computer and use it in GitHub Desktop.
JS: rle
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