UNPKG

@modern-kit/utils

Version:
19 lines (17 loc) 439 B
function flatten(arr, depth = 1) { const result = []; const flooredDepth = Math.floor(depth); const recursive = (arr2, currentDepth) => { for (const item of arr2) { if (Array.isArray(item) && currentDepth < flooredDepth) { recursive(item, currentDepth + 1); } else { result.push(item); } } }; recursive(arr, 0); return result; } export { flatten }; //# sourceMappingURL=index.mjs.map