source: node_modules/es-toolkit/dist/array/sampleSize.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 859 bytes
Line 
1/**
2 * Returns a sample element array of a specified `size`.
3 *
4 * This function takes an array and a number, and returns an array containing the sampled elements using Floyd's algorithm.
5 *
6 * {@link https://www.nowherenearithaca.com/2013/05/robert-floyds-tiny-and-beautiful.html Floyd's algorithm}
7 *
8 * @template T - The type of elements in the array.
9 * @param {T[]} array - The array to sample from.
10 * @param {number} size - The size of sample.
11 * @returns {T[]} A new array with sample size applied.
12 * @throws {Error} Throws an error if `size` is greater than the length of `array`.
13 *
14 * @example
15 * const result = sampleSize([1, 2, 3], 2)
16 * // result will be an array containing two of the elements from the array.
17 * // [1, 2] or [1, 3] or [2, 3]
18 */
19declare function sampleSize<T>(array: readonly T[], size: number): T[];
20
21export { sampleSize };
Note: See TracBrowser for help on using the repository browser.