-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
98 lines (89 loc) · 2.02 KB
/
demo.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>-->
<script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
</head>
<body>
<script>
(function (){
var arr = [
{ name: '1', id: 1 },
{ name: '2', id: 2 },
{ name: '2', id: 22 },
{ name: '3', id: 3 },
{ name: '4', id: 3 },
]
function uniqueName (list, key) {
const set = new Set();
return list.filter(item => {
if (!set.has(item[key])) {
set.add(item[key])
return item
}
})
// return [...set]
}
console.log('uniqueName:', uniqueName(arr, 'name'))
console.log('uniqueName:', uniqueName(arr, 'id'))
})()
</script>
<div id="app">
vue
<p >class Function</p>
</div>
<script>
var tree = [
{
key: 10,
value: 10,
children: [
{
key: 100,
value: 100,
},
{
key: 101,
value: 101,
children: [
{
key: 1000,
value: 1000,
},
{
key: 1001,
value: 1001,
}
],
}
]
}
];
// console.table('difference:', _.difference(tree, [{
// key: 1000,
// value: 1000,
// }]))
function curTree(tree, key) {
return tree.map((node, index) => {
if (node.key === key) {
// console.log('node:', node);
tree.splice(index, 1);
// return node;
}
if (node.children) {
return {
...node,
children: curTree(node.children, key),
};
}
return node;
});
}
console.log('curTree(tree, 1000):', curTree(tree, 1000));
</script>
</body>
</html>