面试.html
2.38 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html>
<head>
</head>
<div style="width:200px;height:100px;background: red">
<div style="height:50%;margin-right:50%;background: blue">
</div>
</div>
//子元素margin-top,margin-bottom的百分比是根据父元素的高度
//子元素margin-left,margin-right的百分比是根据父元素的宽度
<body>
<script>
let a = Array.from(new Array(10000), (item, index) => {
return index;
})
let b = Array.from(new Array(10000), (item, index) => {
return index * 2;
})
let provice = [{
key: 1,
value: '山东',
}, {
key: 2,
value: '河南',
}, {
key: 1,
value: '山西',
},];
let city = [{
key: 1,
value: '青岛',
}, {
key: 2,
value: '郑州',
}, {
key: 2,
value: '安阳',
}, {
key: 3,
value: '太原',
},];
let startTime = new Date().getTime();
// console.log("去重开始 startTime", startTime)
//方法:new Set
// let distinct = function (a, b) {
// return Array.from(new Set([...a, ...b]));
// };
//方法:object
// function distinct(a, b) {
// let obj = {};
// let result = [];
// for (let item of [...a, ...b]) {
// if (!obj[item]) {
// obj[item] = 1;
// result.push(item);
// }
// };
// return result
// };
//面试题延伸
// let citys = {};
// city.forEach((item)=>{
// citys[item] = citys[item] || [];
// citys[item].push(item.value);
// })
// provice.forEach((item)=>{
// item.citys = citys[item.key];
// })
// let endTime = new Date().getTime();
// console.log("去重结束 endTime", endTime)
// console.log("去重用时(毫秒)", endTime - startTime)
function fn() {
var i = 0;
return function fnAdd() {
console.log(i++);
}
}
var fn1 = new fn();
fn2 = new fn();
// fn1();
// fn1();
// fn2();
setTimeout(() => {
console.log("setTimeout 100")
}, 100)
setTimeout(() => {
console.log("setTimeout 0")
}, 0)
for (let i = 0; i < 4; i++) {
console.log('for',i)
}
</script>
</body>
</html>