source: node_modules/es-toolkit/dist/array/flatten.mjs

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

Added visualizations

  • Property mode set to 100644
File size: 514 bytes
Line 
1function flatten(arr, depth = 1) {
2 const result = [];
3 const flooredDepth = Math.floor(depth);
4 const recursive = (arr, currentDepth) => {
5 for (let i = 0; i < arr.length; i++) {
6 const item = arr[i];
7 if (Array.isArray(item) && currentDepth < flooredDepth) {
8 recursive(item, currentDepth + 1);
9 }
10 else {
11 result.push(item);
12 }
13 }
14 };
15 recursive(arr, 0);
16 return result;
17}
18
19export { flatten };
Note: See TracBrowser for help on using the repository browser.