head

说明

获取指定数组的第个元素

源码

用法

head.test.ts
1
import { head } from "../../utility/array/head";
2
3
describe('head tests: ', () => {
4
test('head should return the first field that was in origin array', () => {
5
const received: number[] = [1, 2, 3, 4, 5];
6
const expected = 1;
7
8
const result = head<number>(received);
9
10
expect(result).toBe(expected);
11
});
12
13
test('head should return undefined when receive an empty array', () => {
14
const received: any[] = [];
15
const expected = undefined;
16
17
const result = head<any>(received);
18
19
expect(result).toBe(expected);
20
});
21
});
Copied!
最近更新 1yr ago
复制链接