1.手写代码:输出数组前n大的值
const getNArr = (originArr,n) => { const temp = originArr.slice(0,n+1) const tempSort = temp.sort((a,b)=>a-b) const restArr = originArr.slice(n+1,originArr.length) restArr.forEach((i,idx)=>{ if(i>tempSort[tempSort.length-1]){ tempSort.shift() tempSort.push(i) } }) return tempSort.sort((a,b) => a-b) }
2.promise.all如果有一个reject会怎么样
const p = Promise.all([p1, p2, p3]);
(1)只有 p1、p2、p3 的状态都变成 fulfilled, p 的状态才会变成 fulfilled,
此时p1、p2、p3 的返回值组成一个数组,传递给 p的回调函数。
(2)只要 p1、p2、p3 之中有一个被 rejected,p 的状态就变成 rejected,
此时第一个被 reject 的实例的返回值,会传递给 p 的回调函数。只要有一个变为 rejected,就会调用 Promise .all()的catch
3.antd table fixed列是怎么实现的
css的position:sticky属性
4.position:sticky在低版本无法兼容的浏览器中如何实现
它其实是position:relative和position:fixed的结合,相对于第一个滚动父元素起作用。如果浏览器不兼容,那么可以通过监听滚动来动态设置position为relative和fixed
5.最近的祖先级定位元素指什么
除了static不是,absolute、relative、fixed、sticky都是定位元素