This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]; |