source: node_modules/es-toolkit/dist/array/fill.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: 3.3 KB
Line 
1/**
2 * Fills the whole array with a specified value.
3 *
4 * This function mutates the original array and replaces its elements with the provided value, starting from the specified
5 * start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
6 * entire array.
7 *
8 * @template T - The type of the value to fill the array with.
9 * @param {unknown[]} array - The array to fill.
10 * @param {T} value - The value to fill the array with.
11 * @returns {T[]} The array with the filled values.
12 *
13 * @example
14 * const array = [1, 2, 3];
15 * const result = fill(array, 'a');
16 * // => ['a', 'a', 'a']
17 *
18 * const result = fill(Array(3), 2);
19 * // => [2, 2, 2]
20 *
21 * const result = fill([4, 6, 8, 10], '*', 1, 3);
22 * // => [4, '*', '*', 10]
23 *
24 * const result = fill(array, '*', -2, -1);
25 * // => [1, '*', 3]
26 */
27declare function fill<T>(array: unknown[], value: T): T[];
28/**
29 * Fills elements of an array with a specified value from the start position up to the end of the array.
30 *
31 * This function mutates the original array and replaces its elements with the provided value, starting from the specified
32 * start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
33 * entire array.
34 *
35 * @template T - The type of elements in the original array.
36 * @template U - The type of the value to fill the array with.
37 * @param {Array<T | U>} array - The array to fill.
38 * @param {U} value - The value to fill the array with.
39 * @param {number} [start=0] - The start position. Defaults to 0.
40 * @returns {Array<T | U>} The array with the filled values.
41 *
42 * @example
43 * const array = [1, 2, 3];
44 * const result = fill(array, 'a');
45 * // => ['a', 'a', 'a']
46 *
47 * const result = fill(Array(3), 2);
48 * // => [2, 2, 2]
49 *
50 * const result = fill([4, 6, 8, 10], '*', 1, 3);
51 * // => [4, '*', '*', 10]
52 *
53 * const result = fill(array, '*', -2, -1);
54 * // => [1, '*', 3]
55 */
56declare function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;
57/**
58 * Fills elements of an array with a specified value from the start position up to, but not including, the end position.
59 *
60 * This function mutates the original array and replaces its elements with the provided value, starting from the specified
61 * start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
62 * entire array.
63 *
64 * @template T - The type of elements in the original array.
65 * @template U - The type of the value to fill the array with.
66 * @param {Array<T | U>} array - The array to fill.
67 * @param {U} value - The value to fill the array with.
68 * @param {number} [start=0] - The start position. Defaults to 0.
69 * @param {number} [end=arr.length] - The end position. Defaults to the array's length.
70 * @returns {Array<T | U>} The array with the filled values.
71 *
72 * @example
73 * const array = [1, 2, 3];
74 * const result = fill(array, 'a');
75 * // => ['a', 'a', 'a']
76 *
77 * const result = fill(Array(3), 2);
78 * // => [2, 2, 2]
79 *
80 * const result = fill([4, 6, 8, 10], '*', 1, 3);
81 * // => [4, '*', '*', 10]
82 *
83 * const result = fill(array, '*', -2, -1);
84 * // => [1, '*', 3]
85 */
86declare function fill<T, U>(array: Array<T | U>, value: U, start: number, end: number): Array<T | U>;
87
88export { fill };
Note: See TracBrowser for help on using the repository browser.