File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ /**
4
+ * Expose `arrayFlatten`.
5
+ */
6
+ module . exports = arrayFlatten
7
+
3
8
/**
4
9
* Recursive flatten function with depth.
5
10
*
8
13
* @param {Number } depth
9
14
* @return {Array }
10
15
*/
11
- function flattenDepth ( array , result , depth ) {
16
+ function flattenWithDepth ( array , result , depth ) {
12
17
for ( var i = 0 ; i < array . length ; i ++ ) {
13
18
var value = array [ i ]
14
19
15
20
if ( depth > 0 && Array . isArray ( value ) ) {
16
- flattenDepth ( value , result , depth - 1 )
21
+ flattenWithDepth ( value , result , depth - 1 )
17
22
} else {
18
23
result . push ( value )
19
24
}
@@ -50,10 +55,10 @@ function flattenForever (array, result) {
50
55
* @param {Number } depth
51
56
* @return {Array }
52
57
*/
53
- module . exports = function ( array , depth ) {
58
+ function arrayFlatten ( array , depth ) {
54
59
if ( depth == null ) {
55
60
return flattenForever ( array , [ ] )
56
61
}
57
62
58
- return flattenDepth ( array , [ ] , depth )
63
+ return flattenWithDepth ( array , [ ] , depth )
59
64
}
You can’t perform that action at this time.
0 commit comments