_join

说明

将数组中的所有元素转换为由 separator 分隔的字符串

源码

用法

_join.test.ts
1
import { _join } from "../../utility/array/_join";
2
3
describe('Method _join test:', () => {
4
test('_join() should return the empty string when receive an empty array', () => {
5
const received = {
6
arr: [],
7
separator: '',
8
};
9
const expected = '';
10
11
const result = _join(received.arr, received.separator);
12
13
expect(result).toBe(expected);
14
});
15
16
test('_join() should return the composed string when receive an array maked by number', () => {
17
const received = {
18
arr: [1, 2, 3, 4, 5],
19
separator: '',
20
};
21
const expected = '12345';
22
23
const result = _join(received.arr, received.separator);
24
25
expect(result).toBe(expected);
26
});
27
28
test('_join() can config your own separator', () => {
29
const received = {
30
arr: ['a', 'b', 'c', 'd', 'e'],
31
separator: '-',
32
};
33
const expected = 'a-b-c-d-e';
34
35
const result = _join(received.arr, received.separator);
36
37
expect(result).toBe(expected);
38
});
39
});
Copied!
最近更新 1yr ago
复制链接