UNPKG

cerceis-lib

Version:

Contains list of quality of life functions that is written in TypeScript and es6

64 lines (62 loc) 2.34 kB
declare const FromArray: { /** * Returns one or more random elements from an array. * @param arr Input array. * @param noOfResult Number of results to return (default 1). * @param returnIndex Return index positions instead of values. */ getRandom<T>(arr: T[], noOfResult?: number, returnIndex?: boolean): T[] | number[]; /** * Find and return the largest N numbers. * @param numbers Array of numbers. * @param n Number of results to return (default 1). * @param returnIndex Return indices instead of values. */ getLargest(numbers: number[], n?: number, returnIndex?: boolean): number[]; /** * Find and return the smallest N numbers. * @param numbers Array of numbers. * @param n Number of results to return (default 1). * @param returnIndex Return indices instead of values. */ getSmallest(numbers: number[], n?: number, returnIndex?: boolean): number[]; /** * Return the intersection of two arrays. * @param arrA Array A. * @param arrB Array B. * @param duplicated Include duplicate matches. */ getIntersect<T>(arrA: T[], arrB: T[], duplicated?: boolean): T[]; /** * Randomly shuffle an array in-place (Fisher-Yates). * @param arr Array to shuffle. */ shuffle<T>(arr: T[]): T[]; /** * The Thanos snap — removes roughly half the elements randomly. * Mutates the original array. * @param arr Input array. */ thanosSnap<T>(arr: T[]): T[]; /** * Convert a 2D array ([[key, value], ...]) into an object. * @param arr Input 2D array. */ toObject<V>(arr: [string | number, V][]): Record<string | number, V>; /** * Split an array into groups by ratio. * ex) [1,2,3,4] split [1,3] → {1:[1], 2:[2,3,4]} * Remainder goes into "extra" if it doesn't fit. * @param arr Array to split. * @param ratio Ratio to split into. */ splitInto<T>(arr: T[], ratio: number[]): Record<string, T[]>; /** * Log array elements to console, optionally limited to a range. * @param arr Array to log. * @param from Starting index (inclusive), default 0. * @param to Ending index (exclusive), default arr.length. */ log<T>(arr: T[], from?: number, to?: number): void; }; export { FromArray };