24 lines
610 B
JavaScript
24 lines
610 B
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
function flatten(arr, depth = 1) {
|
|
const result = [];
|
|
const flooredDepth = Math.floor(depth);
|
|
const recursive = (arr, currentDepth) => {
|
|
for (let i = 0; i < arr.length; i++) {
|
|
const item = arr[i];
|
|
if (Array.isArray(item) && currentDepth < flooredDepth) {
|
|
recursive(item, currentDepth + 1);
|
|
}
|
|
else {
|
|
result.push(item);
|
|
}
|
|
}
|
|
};
|
|
recursive(arr, 0);
|
|
return result;
|
|
}
|
|
|
|
exports.flatten = flatten;
|