UNPKG

diginext-utils

Version:
18 lines 662 B
/** * Gets N random elements from an array. * If N is not specified or greater than array length, returns all elements shuffled. * * @template T - The type of elements in the array * @param array - The array to sample from * @param n - Number of elements to sample (optional) * @returns A new array with N random elements * * @example * ```ts * sample([1, 2, 3, 4, 5], 2); // Two random elements, e.g., [3, 1] * sample(['a', 'b', 'c']); // All elements in random order * sample([1, 2, 3], 5); // All elements in random order (n > length) * ``` */ export declare function sample<T>(array: T[], n?: number): T[]; //# sourceMappingURL=sample.d.ts.map