thorish
Version:
This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.
31 lines (30 loc) • 1.22 kB
TypeScript
/**
* Finds all indexes of a given iterable which match the given predicate.
*/
export declare function findAllIndex<X>(arr: Iterable<X>, predicate: (x: X) => boolean): number[];
/**
* Checks whether the larger array contains the passed sub-array at any index. O(n*m).
*/
export declare function arrayContainsSub<X>(arr: X[], sub: X[]): boolean;
/**
* Finds the first index of the subarray in the larger array. This is O(n*m).
*
* Returns `-1` if not found.
*/
export declare function findSubArray<X>(arr: X[], sub: X[]): number;
/**
* Removes the given index from the array, returning it if the index is valid.
*
* Swaps the last value of the array into the new position.
*
* Has {@link Array.at}-like semantics, supporting negative addressing.
*/
export declare function arraySwapRemoveAt<X>(arr: X[], at: number): X | undefined;
/**
* Inserts a value at the given index in the array by swapping any previous value to the end.
*
* This 'always works' because indexes <=0 are treated as zero, and indexes >=length are treated as a push.
*
* Has {@link Array.at}-like semantics, supporting negative addressing.
*/
export declare function arraySwapInsertAt<X>(arr: X[], at: number, value: X): void;