UNPKG

@modern-kit/utils

Version:
21 lines (18 loc) 461 B
'use strict'; 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; } exports.flatten = flatten; //# sourceMappingURL=index.cjs.map