run-length
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Run length encode and decoder

Installation

npm install --save run-length

Example

Works on arrays and is for repeated sequences.

import { encode, decode } from 'run-length';
 
// generate array with repeated sequence as demo
const length = 30;
const arr = Array.from({ length }, (_, i) => (i < length / 2 ? 1 : 0));
 
console.log(arr);
// [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
console.log(encode(arr));
// [ [ 15, 1 ], [ 15, 0 ] ]
console.log(decode(encode(arr)));
// [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

Author

Dugagjin Lashi

License

MIT

Package Sidebar

Install

npm i run-length

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

3.5 kB

Total Files

5

Last publish

Collaborators

  • dugagjinll