fill

说明

使用 value 值来填充(替换) array. 从 start 位置开始, 到 end 位置结束(但不包含 end 位置).

源码

用法

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