igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
31 lines (30 loc) • 1.07 kB
TypeScript
/**
* A collection of static array utility functions.
*/
export default class ArrayPoly {
/**
* Filter elements in an array to only unique values, using the result of a mapper function to
* test for equality. Usage:
*
* <code>
* ['a', 'b', 'c', 'a', 'A', 'C'].filter(ArrayPoly.filterUniqueMapped((str) => str.toUpperCase());
* </code>
*/
static filterUniqueMapped<T>(mapper: (arg: T) => unknown): (value: T, idx: number, values: T[]) => boolean;
/**
* Reduce elements in an array to chunks of size {@link limit}.
*
* <code>
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].reduce(ArrayPoly.reduceChunk(3), []);
* </code>
*/
static reduceChunk<T>(limit: number): (previous: T[][], current: T, idx: number, array: T[]) => T[][];
/**
* Reduce elements in an array to only unique values. Usage:
*
* <code>
* [1, 2, 3, 1, 1, 3].reduce(ArrayPoly.reduceUnique(), []);
* </code>
*/
static reduceUnique<T>(): (previous: T[], current: T, idx: number, array: T[]) => T[];
}