Skip to content

Commit 4341d22

Browse files
committed
perf(Array.flat): use push(...) instead of concat
1 parent 40e089e commit 4341d22

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Array.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ define(Array.prototype, {
1616
return this;
1717
},
1818

19-
flat: function (depth: number = 1) {
19+
flat: function <T>(depth: number = 1) {
2020
return this.reduce(
2121
(acc: any, val: any) =>
22-
(Array.isArray(val) && depth >= 1) || depth === -1 ? acc.concat(val.flat(depth--)) : acc.concat(val),
22+
(Array.isArray(val) && depth >= 1) || depth === -1 ? acc.push(...val.flat(depth--)) : acc.push(val),
2323
[]
2424
);
2525
},

0 commit comments

Comments
 (0)