drop

说明

创建一个切片数组, 去除array前面的n个元素

源码

用法

drop.test.ts
1
import { drop } from "../../utility/array/drop";
2
3
describe('drop tests', () => {
4
test('drop should return an empty array when receive an empty array', () => {
5
const received: number[] = [];
6
const expected = [];
7
8
const result = drop<number>(received);
9
10
expect(result.length).toBe(expected.length);
11
});
12
13
test('drop should return the droped array by using customized number when receive an array being composed of number', () => {
14
const received: number[] = [1, 2, 3, 4, 5, 6];
15
const expected: number[] = [4, 5, 6];
16
17
const result = drop<number>(received, 3);
18
19
result.forEach((v, i) => {
20
expect(v).toBe(expected[i]);
21
});
22
});
23
24
test('drop should not change the origin array', () => {
25
const received: number[] = [100, 300, 500];
26
const expected: number[] = [100, 300, 500];
27
28
const result = drop<number>(received, 0);
29
result.push(700, 900);
30
31
expect(result.length).toBe(5);
32
received.forEach((v, i) => {
33
expect(v).toBe(expected[i]);
34
});
35
});
36
});
Copied!
最近更新 1yr ago
复制链接