source: node_modules/es-toolkit/dist/array/flatten.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: 743 bytes
Line 
1/**
2 * Flattens an array up to the specified depth.
3 *
4 * @template T - The type of elements within the array.
5 * @template D - The depth to which the array should be flattened.
6 * @param {T[]} arr - The array to flatten.
7 * @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
8 * @returns {Array<FlatArray<T[], D>>} A new array that has been flattened.
9 *
10 * @example
11 * const arr = flatten([1, [2, 3], [4, [5, 6]]], 1);
12 * // Returns: [1, 2, 3, 4, [5, 6]]
13 *
14 * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15 * // Returns: [1, 2, 3, 4, 5, 6]
16 */
17declare function flatten<T, D extends number = 1>(arr: readonly T[], depth?: D): Array<FlatArray<T[], D>>;
18
19export { flatten };
Note: See TracBrowser for help on using the repository browser.