Sha256: 43d89bc9ec2b6b06bbb25146ea1f1701dfdfa28cb73b99148a61b3bfa1a1363f
Contents?: true
Size: 453 Bytes
Versions: 66
Compression:
Stored size: 453 Bytes
Contents
class RunLengthEncoding { static encode(plaintext: string): string { return plaintext.replace(/([\w\s])\1*/g, (match) => { return match.length > 1 ? match.length + match[0] : match[0] }) } static decode(cypher: string): string { return cypher.replace(/(\d+)(\w|\s)/g, (_match, repeats, char) => { return new Array(+repeats + 1).join(char) }) } } export default RunLengthEncoding
Version data entries
66 entries across 66 versions & 1 rubygems