source: node_modules/es-toolkit/dist/array/takeWhile.d.mts

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

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * Returns a new array containing the leading elements of the provided array
3 * that satisfy the provided predicate function. It stops taking elements as soon
4 * as an element does not satisfy the predicate.
5 *
6 * @template T - The type of elements in the array.
7 * @param {T[]} arr - The array to process.
8 * @param {(element: T, index: number, array: readonly T[]) => boolean} shouldContinueTaking - The predicate function that is called with each element, its index, and the array. Elements are included in the result as long as this function returns true.
9 * @returns {T[]} A new array containing the leading elements that satisfy the predicate.
10 *
11 * @example
12 * // Returns [1, 2]
13 * takeWhile([1, 2, 3, 4], x => x < 3);
14 *
15 * @example
16 * // Returns []
17 * takeWhile([1, 2, 3, 4], x => x > 3);
18 *
19 * @example
20 * // Using index parameter
21 * takeWhile([10, 20, 30, 40], (x, index) => index < 2);
22 * // Returns: [10, 20]
23 */
24declare function takeWhile<T>(arr: readonly T[], shouldContinueTaking: (element: T, index: number, array: readonly T[]) => boolean): T[];
25
26export { takeWhile };
Note: See TracBrowser for help on using the repository browser.