_concat

说明

将给定的任意数量的值追加至源数组

源码

用法

_concat.test.ts
1
import { _concat } from "../../utility/array/_concat";
2
3
describe('_concat', () => {
4
test('_concat should return an new array being composed of number', () => {
5
const received = [1, 2, 3, 4, 5];
6
const expected = [1, 2, 3, 4, 5, 6, 7, 8];
7
8
const result = _concat<number>(received, 6, 7, 8);
9
10
for (const [i, v] of result.entries()) {
11
expect(v).toBe(expected[i]);
12
}
13
14
// Should not change the origin array
15
expect(received.length).toBe(5);
16
});
17
18
test('_concat should return an new array being composed of any value', () => {
19
const received: any[] = [1, 0, '', undefined, null, [[100]], { name: 'ddzy' }];
20
const expected = 10;
21
22
const result = _concat<any>(received, [[200], [300]], { age: 21 });
23
24
expect(result.length).toBe(expected);
25
});
26
});
Copied!
最近更新 1yr ago
复制链接