杭州 整数智能 校招 笔试
2023-02-22 16:00
1.左右两边占据屏幕 25% 中间 50% 自适应 flex
2.把 url 中的参数转成对象
ts
let httpUrlStr = 'https://www.whatever.com?name=zhangsan&age=18'
function urlToObj(url) {
const result = {}
const urlArray = url.split('?')[1].split('&')
urlArray.forEach(item => {
const res = item.split('=')
const key = res[0]
const val = res[1]
result[key] = val
})
return result
}
console.log(urlToObj(httpUrlStr))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
3.数组去重
4.找出字符串中出现最多次数的字符和次数
ts
const str = 'ababajshbaasdaaaa'
// { char:'a',count:9 }
function computeString(str) {
const compute = {}
for (let i = 0; i < str.length; i++) {
let key = str[i]
if (compute[key]) {
compute[key] = compute[key] + 1
} else {
compute[key] = 1
}
}
let max
console.log(Object.values(compute))
Object.values(compute).forEach(item => {
if (max) {
if (max < item) {
max = item
}
} else {
max = item
}
})
let char
for (const item in compute) {
if (compute[item] == max) {
char = item
}
}
return { char, count: max }
}
console.log(computeString(str))
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
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
- 5.防抖
ts
function debounce(callback, time) {
let timer = null
return (...args) => {
if (timer) {
clearTimeout(timer)
timer = null
}
timer = setTimeout(() => {
callback(...args)
}, time)
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12