dropRight

说明

从源数组的右侧开始, 舍弃指定个数的值

源码

用法

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