/** * Groups elements of an array by a key or function. * @param arr - The array to group. * @param keyFn - A function that returns the key to group by. * @returns An object where keys are the result of the key function and values are arrays of grouped items. */ export declare function groupBy(arr: T[], keyFn: (item: T) => K): { [key: string]: T[]; }; /** * Flattens a nested array into a single-level array. * @param arr - The array to flatten. * @returns A new array with all nested arrays flattened. */ export declare function flatten(arr: T[][]): T[]; /** * Removes duplicate values from an array. * @param arr - The array to deduplicate. * @returns A new array with unique values. */ export declare function unique(arr: T[]): T[]; /** * Finds common elements between two arrays. * @param arr1 - The first array. * @param arr2 - The second array. * @returns An array of elements present in both arrays. */ export declare function intersection(arr1: T[], arr2: T[]): T[]; /** * Finds elements that are in one array but not in another. * @param arr1 - The first array. * @param arr2 - The second array. * @returns An array of elements present in the first array but not in the second. */ export declare function difference(arr1: T[], arr2: T[]): T[]; /** * Randomly shuffles the elements of an array. * @param arr - The array to shuffle. * @returns A new array with the elements shuffled. */ export declare function shuffle(arr: T[]): T[]; /** * Partitions an array into groups based on a predicate function. * @param arr - The array to partition. * @param predicate - A function that determines the group for each element. * @returns An array containing two arrays: the first with elements that satisfy the predicate, the second with elements that do not. */ export declare function partition(arr: T[], predicate: (item: T) => boolean): [T[], T[]]; /** * Sorts an array of objects based on a key or function. * @param arr - The array to sort. * @param keyOrFn - The key or function to sort by. * @param ascending - Whether to sort in ascending order (default is true). * @returns A new array sorted based on the key or function. */ export declare function sortBy(arr: T[], keyOrFn: keyof T | ((item: T) => any), ascending?: boolean): T[]; /** * Combines two arrays into a single array of pairs. * @param arr1 - The first array. * @param arr2 - The second array. * @returns An array of pairs, where each pair is from the corresponding positions in the input arrays. */ export declare function zip(arr1: T[], arr2: U[]): [T, U][]; /** * Reduces an array into a single value based on a key or function. * @param arr - The array to reduce. * @param keyOrFn - The key or function to group by. * @param reducer - A function that reduces the values in each group. * @param initialValue - The initial value for the reduction. * @returns An object where keys are the result of the key or function and values are the reduced values. */ export declare function reduceBy(arr: T[], keyOrFn: keyof T | ((item: T) => K), reducer: (acc: V, item: T) => V, initialValue: V): { [key in K]: V; }; /** * Groups elements of an array into chunks of a specified size. * @param arr - The array to chunk. * @param size - The size of each chunk. * @returns An array of arrays, where each sub-array is a chunk of the original array. */ export declare function chunk(arr: T[], size: number): T[][]; /** * Finds the first element that matches the predicate function. * @param arr - The array to search. * @param predicate - A function that tests each element. * @returns The first element that matches the predicate, or undefined if no match is found. */ export declare function findFirst(arr: T[], predicate: (item: T) => boolean): T | undefined; /** * Finds the last element that matches the predicate function. * @param arr - The array to search. * @param predicate - A function that tests each element. * @returns The last element that matches the predicate, or undefined if no match is found. */ export declare function findLast(arr: T[], predicate: (item: T) => boolean): T | undefined; /** * Computes the difference between two arrays based on a key function. * @param arr1 - The first array. * @param arr2 - The second array. * @param keyFn - A function that returns the key to compare. * @returns An array of elements present in the first array but not in the second. */ export declare function differenceBy(arr1: T[], arr2: T[], keyFn: (item: T) => K): T[]; /** * Finds the union of two arrays based on a key function. * @param arr1 - The first array. * @param arr2 - The second array. * @param keyFn - A function that returns the key to compare. * @returns An array of unique elements from both arrays. */ export declare function unionBy(arr1: T[], arr2: T[], keyFn: (item: T) => K): T[]; /** * Computes the symmetric difference between two arrays based on a key function. * @param arr1 - The first array. * @param arr2 - The second array. * @param keyFn - A function that returns the key to compare. * @returns An array of elements that are in either array but not in both. */ export declare function symmetricDifferenceBy(arr1: T[], arr2: T[], keyFn: (item: T) => K): T[]; /** * Computes the Cartesian product of multiple arrays. * @param arrays - The arrays to compute the Cartesian product of. * @returns An array of all possible combinations of elements from the input arrays. */ export declare function cartesianProduct(...arrays: T[][]): T[][]; /** * Computes the median value of a numeric array. * @param arr - The array of numbers. * @returns The median value. */ export declare function median(arr: number[]): number; /** * Removes falsy values from an array. * @param arr - The array to compact. * @returns A new array without falsy values. */ export declare function compact(arr: T[]): T[]; /** * Creates an array of numbers within a specified range. * @param start - The start of the range. * @param end - The end of the range. * @param step - The step between each number (default is 1). * @returns An array of numbers within the specified range. */ export declare function range(start: number, end: number, step?: number): number[];