Skip to content

Commit 41752bf

Browse files
committed
collapse array
1 parent 1d47e35 commit 41752bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

collapse.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function collapse(n) {
2+
const arr = this;
3+
const result = [];
4+
5+
for (let i = 0; i < arr.length; i++) {
6+
if (Array.isArray(arr[i])) {
7+
result.push(...arr[i]);
8+
} else {
9+
result.push(arr[i]);
10+
}
11+
}
12+
13+
return result;
14+
}

0 commit comments

Comments
 (0)