run-length
v1.0.1
Published
run length encoder and decoder
Downloads
12
Readme
Run length encode and decoder
Installation
npm install --save run-lengthExample
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
