main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
785 bytes
|
Line | |
---|
1 | import baseFlatten from './_baseFlatten.js';
|
---|
2 | import toInteger from './toInteger.js';
|
---|
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 | export default flattenDepth;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.