蚂蚁
问答:
react16.8新增了哪些hooks,怎么使用的?
vue2、3的响应式原理,有什么区别,为什么?
Promise all race any 区别、使用场景?
笔试
[a,b] = [b,a]
let flag = false
setTimeout(()=>flag=true,3000)
setTimeout(()=>{
while(!flag){
if(flag) break
}
console.log('hello')
},0)
const list = [ { id: 04, pid: 03 },{ id: 01, pid: null },{ id: 02, pid: null },
{ id: 03, pid: 01 }, { id: 05, pid: 01 }, { id: 06, pid: 03 }, { id: 07, pid: 02 },
{ id: 09, pid: 02 }, { id: 10, pid: 07 }]
function toTree(data) {
let result = [];
let obj = {};
data.forEach(item => {
obj[item.id] = Object.assign(item, obj[item.id] || {});
if (item.pid) {
let parent = obj[item.pid] || {};
parent.child = parent.child || [];
parent.child.push(item);
obj[item.pid] = parent;
}
else {
result.push(obj[item.id])
}
})
return result;
}