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

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

Added visualizations

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