数组去重

今天处理下数组的去重。

基础款

要求

1
2
输入in ===> list = [1,2,3,1]
输出out ===> unionList = [1,2,3]

进阶

要求:

1
2
输入in ===> list = [{x: 1, y: 2},{x: 1, y: 1},{x: 1, y: 1}]
输出out ===> unionList = [{x: 1, y: 2},{x: 1, y: 1}]

究极体

要求:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
输入in ===> list = [
{
code: 1,
name: '哈',
batch: '1-1',
other: 'yiyi',
},
{
code: 1,
name: '哈',
batch: '1-2',
other: 'yier',
},
{
code: 1,
name: '哈',
batch: '1-1',
other: 'yier',
},
{
code: 2,
name: '呵',
batch: '2-1',
other: 'eryi',
}
]

primaryKey: code + batch

输出out ===> unionList = [
{
code: 1,
name: '哈',
batch: '1-1',
other: 'yiyi',
},
{
code: 1,
name: '哈',
batch: '1-2',
other: 'yier',
},
{
code: 2,
name: '呵',
batch: '2-1',
other: 'eryi',
}
]
© 2019 lvbin's Blog All Rights Reserved.
Theme by hiero