Skip to content

Commit 085410a

Browse files
committed
Decrement depth when we recurse
1 parent 61d3c15 commit 085410a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

array-flatten.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
* @return {Array}
88
*/
99
var flatten = function (array, result, depth) {
10-
depth--;
11-
1210
for (var i = 0; i < array.length; i++) {
13-
if (depth > -1 && Array.isArray(array[i])) {
14-
flatten(array[i], result, depth);
11+
if (depth > 0 && Array.isArray(array[i])) {
12+
flatten(array[i], result, depth - 1);
1513
} else {
1614
result.push(array[i]);
1715
}

0 commit comments

Comments
 (0)