Skip to content

Commit 2730ffd

Browse files
day 26 task complete
1 parent c48bd0a commit 2730ffd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

day26/leetcode2625.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 2625. Flatten Deeply Nested Array
2+
// https://leetcode.com/problems/flatten-deeply-nested-array/
3+
4+
/**
5+
* @param {Array} arr
6+
* @param {number} depth
7+
* @return {Array}
8+
*/
9+
var flat = function (arr, n) {
10+
let res = []
11+
function r(arr, depth) {
12+
for (let item of arr) {
13+
if (Array.isArray(item) && depth < n) {
14+
r(item, depth + 1)
15+
} else {
16+
res.push(item)
17+
}
18+
}
19+
20+
return res;
21+
}
22+
23+
return r(arr, 0)
24+
};

0 commit comments

Comments
 (0)