Skip to content

Instantly share code, notes, and snippets.

View santidalmasso's full-sized avatar

Santi Dalmasso santidalmasso

View GitHub Profile
@santidalmasso
santidalmasso / main.ts
Last active March 7, 2022 02:33
RLE solution
type RunLengthEncodedString = [string, number][];
// given a string, return each repeating character and it's run count, for example:
// "aaaabbbbccc" => [["a", 4], ["b", 3], ["c", 3]]
//
// see https://en.wikipedia.org/wiki/Run-length_encoding
export function rle(plain: String): RunLengthEncodedString {
if (plain.length === 0) return [];
const encodedString: RunLengthEncodedString = [];
let currentChar: string = plain[0];