toFlatArrayOutPlace

说明

数组扁平化(非原地算法)

源码

用法

toFlatArrayOutPlace.test.ts
1
import { toFlatArrayOutPlace } from "../../utility/array/toFlatArrayOutPlace";
2
3
describe('toFlatArrayOutPlace', () => {
4
test('toFlatArrayOutPlace should flatten the origin array', () => {
5
const received = [
6
'duan',
7
1998,
8
[
9
'a',
10
'b',
11
[
12
'c',
13
'd',
14
[
15
'e',
16
'f',
17
123
18
],
19
],
20
],
21
{
22
name: 'duan',
23
age: 20,
24
},
25
];
26
const expected = [
27
'duan',
28
1998,
29
'a',
30
'b',
31
'c',
32
'd',
33
'e',
34
'f',
35
123,
36
{ name: 'duan', age: 20 },
37
];
38
39
const result = toFlatArrayOutPlace(received);
40
41
for (const [outerI, outerV] of result.entries()) {
42
expect(outerV).toEqual(expected[outerI]);
43
}
44
});
45
});
Copied!
最近更新 1yr ago
复制链接