|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
943 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Returns a new array containing the first `count` elements from the input array `arr`.
|
|---|
| 3 | * If `count` is greater than the length of `arr`, the entire array is returned.
|
|---|
| 4 | *
|
|---|
| 5 | * @template T - Type of elements in the input array.
|
|---|
| 6 | *
|
|---|
| 7 | * @param {T[]} arr - The array to take elements from.
|
|---|
| 8 | * @param {number} count - The number of elements to take.
|
|---|
| 9 | * @param {unknown} guard - If truthy, ignores `count` and defaults to 1.
|
|---|
| 10 | * @returns {T[]} A new array containing the first `count` elements from `arr`.
|
|---|
| 11 | *
|
|---|
| 12 | * @example
|
|---|
| 13 | * // Returns [1, 2, 3]
|
|---|
| 14 | * take([1, 2, 3, 4, 5], 3);
|
|---|
| 15 | *
|
|---|
| 16 | * @example
|
|---|
| 17 | * // Returns ['a', 'b']
|
|---|
| 18 | * take(['a', 'b', 'c'], 2);
|
|---|
| 19 | *
|
|---|
| 20 | * @example
|
|---|
| 21 | * // Returns [1, 2, 3]
|
|---|
| 22 | * take([1, 2, 3], 5);
|
|---|
| 23 | *
|
|---|
| 24 | * @example
|
|---|
| 25 | * // Returns [[1], [1], [1]]
|
|---|
| 26 | * const arr = [1, 2, 3];
|
|---|
| 27 | * const result = arr.map((v, i, array) => take(array, i, true));
|
|---|
| 28 | */
|
|---|
| 29 | declare function take<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
|
|---|
| 30 |
|
|---|
| 31 | export { take };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.