1
|
var baseFlatten = require('./_baseFlatten'),
|
2
|
toInteger = require('./toInteger');
|
3
|
|
4
|
/**
|
5
|
* Recursively flatten `array` up to `depth` times.
|
6
|
*
|
7
|
* @static
|
8
|
* @memberOf _
|
9
|
* @since 4.4.0
|
10
|
* @category Array
|
11
|
* @param {Array} array The array to flatten.
|
12
|
* @param {number} [depth=1] The maximum recursion depth.
|
13
|
* @returns {Array} Returns the new flattened array.
|
14
|
* @example
|
15
|
*
|
16
|
* var array = [1, [2, [3, [4]], 5]];
|
17
|
*
|
18
|
* _.flattenDepth(array, 1);
|
19
|
* // => [1, 2, [3, [4]], 5]
|
20
|
*
|
21
|
* _.flattenDepth(array, 2);
|
22
|
* // => [1, 2, 3, [4], 5]
|
23
|
*/
|
24
|
function flattenDepth(array, depth) {
|
25
|
var length = array == null ? 0 : array.length;
|
26
|
if (!length) {
|
27
|
return [];
|
28
|
}
|
29
|
depth = depth === undefined ? 1 : toInteger(depth);
|
30
|
return baseFlatten(array, depth);
|
31
|
}
|
32
|
|
33
|
module.exports = flattenDepth;
|