23秋招-神策数据前端一面-面经
时间:2022 年 8 月 31 日。
base: 深圳
时长:40 min 左右。
自我介绍都免了,全程做题,感觉是被 KPI 了。
一共三道题(一个 CSS,一个算法题,一个 JS 处理数据的题)。
CSS
三列布局,中间自适应,左右两边不随中间滚动。
flex 布局,左右使用 position: fixed,此时已脱离文档流,因此要通过left: 0; right: 0 分别指定侧边栏的位置,通过 margin: 0 200px; 避免 center 覆盖左右侧边栏。
<!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.0"
/>
<title>Document</title>
<style>
.container {
display: flex;
width: 100%;
height: 600px;
}
.left, .right {
width: 200px;
height: 300px;
background-color: red;
position: fixed;
}
.left {
left: 0;
}
.right {
right: 0;
}
.center {
flex-grow: 1;
height: 100%;
background-color: yellow;
margin: 0 200px;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
JS
(1)二叉树的先序遍历(先写的递归,然后写的迭代)
面试官提了个问题:如何避免重复访问某个节点?
这个问题是在我写完先序遍历的迭代法后问的,我的回答是不会重复访问某个节点。面试官说:”你再好好想想“。淦,想了一下,迭代确实不会重复访问啊。然后我就说,迭代不会重复访问,递归会重复访问(避免重复访问的方法,我的回答是弄一个 hash 映射)。他也没说什么了,感觉是他问错代码了,就是递归才会重复访问。
(2)扁平数组转树
const items = [
{
id: 1,
name: 'node1',
parentId: -1
},
{
id: 2,
name: 'node11',
parentId: 1
},
{
id: 3,
name: 'node12',
parentId: 1
},
{
id: 4,
name: 'node2',
parentId: 2
},
{
id: 5,
name: 'node21',
parentId: 2
},
{
id: 6,
name: 'node22',
parentId: 2
},
{
id: 7,
name: 'node221',
parentId: 6
}
] 写完答案后,发现面试官给的数据有问题,有两个根节点了。面试官看我发现了,就让我改成一个根节点。(还好留意了一下,不然又要调试半天)
function arrayToTree(items) {
let res = []
function getChildren(res, pid) {
for (const item of items) {
if (item.parentId === pid) {
const newItem = { ...item, children: [] }
res.push(newItem)
getChildren(newItem.children, newItem.id)
}
}
}
getChildren(res, -1)
return res
}
console.log(JSON.stringify(arrayToTree(items), null, 2)) 三道题做完,接近 40分钟了。反问了三个问题:
- 相关业务及技术栈;
- 对我的简历有什么评价(面试官一进来就说先来做一个题,我说我是不是先做个自我介绍,他说我这边有你的简历,上面都写了,淦)面试官的回答:我自己简历都写不好,没有什么建议可以给到你。
- 如果能过的话后面是什么流程?大概三天出结果。
应该是 KPI 选手了。。。
9 月 2 日更新:收到了二面通知,没想到做三个题是认真的。哈哈哈哈~
#23届秋招笔面经##神策数据##前端面经#