_concat

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/array/_concat

说明

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

用法

_concat.ts
_concat.test.ts
import { _concat } from "./ddzy/utility/array/_concat";
// ? 纯数字数组
const s1 = [1, 2, 3, 4, 5];
const p1 = _concat<number>(s1, 6, 7, 8);
console.log(p1);
s1.push(6);
console.log(s1);
console.log('------------------');
// ? 任意值数组
const s2: any[] = [1, 0, '', undefined, null, [[100]], { name: 'ddzy' }];
const p2 = _concat<any>(s2, [[200], [300]], { age: 21 });
console.log(p2);
console.log('-------------------');
import { _concat } from "../../utility/array/_concat";
describe('_concat', () => {
test('_concat should return an new array being composed of number', () => {
const received = [1, 2, 3, 4, 5];
const expected = [1, 2, 3, 4, 5, 6, 7, 8];
const result = _concat<number>(received, 6, 7, 8);
for (const [i, v] of result.entries()) {
expect(v).toBe(expected[i]);
}
// Should not change the origin array
expect(received.length).toBe(5);
});
test('_concat should return an new array being composed of any value', () => {
const received: any[] = [1, 0, '', undefined, null, [[100]], { name: 'ddzy' }];
const expected = 10;
const result = _concat<any>(received, [[200], [300]], { age: 21 });
expect(result.length).toBe(expected);
});
});