本人一年半工作經(jīng)驗(yàn)。面的是麥哲倫蹈丸。
- 自我介紹
- 問了一下項(xiàng)目的內(nèi)容成黄,你覺得你這段工作期間最好的產(chǎn)出是什么?
- 然后問了一下項(xiàng)目細(xì)節(jié)逻杖。
- 怎么避免React組件的重復(fù)渲染奋岁。(shouldComponentUpdate,React.memo荸百,useMemo闻伶,useCallback)
- 怎么避免Vue組件的重復(fù)渲染(v-once,keep-alive够话,避免頻繁的修改Vue的data蓝翰,computed屬性緩存)
- Vue nextTick的原理能說一下嗎?(巴拉巴拉)
- webpack常用配置項(xiàng)是什么女嘲?(entry, output, module.rules, optimize.splitChunks畜份,mode)
- 如果要使用less,那么webpack的css loader怎么配置欣尼?(style-loader, css-loader, less-loader爆雹,生產(chǎn)環(huán)境是minicssextract.loader,css-loader, less-loader)
- 好愕鼓,我們來做題吧
// 請(qǐng)實(shí)現(xiàn)一個(gè)調(diào)度器钙态,這個(gè)調(diào)度器保證任務(wù)的并發(fā)數(shù)為2
class schedular {
// task是一個(gè)函數(shù),會(huì)返回一個(gè)promise拒啰,add也會(huì)返回一個(gè)promise驯绎,add的promise根據(jù)task的promise狀態(tài)改變
add (task) {
}
}
const task = (duration, order) => new Promise((resolve) => {
setTimeout(() => {
resolve(order);
}, duration);
});
// 開始測(cè)試
const schedular = new Schedular();
schedular.add(task(100, 1)).then(res => console.log(res));
schedular.add(task(500, 2)).then(res => console.log(res));
schedular.add(task(300, 3)).then(res => console.log(res));
schedular.add(task(50, 4)).then(res => console.log(res));
// 結(jié)果應(yīng)該為1, 3, 4, 2
根據(jù)上面的題目完慧,修改schedular的add函數(shù)為下面的代碼谋旦,然后根據(jù)優(yōu)先級(jí)priority進(jìn)行調(diào)度工作。優(yōu)先級(jí)越小越優(yōu)先屈尼。
// add函數(shù)變更
add (task, priority) {
}
// 測(cè)試代碼變更
const schedular = new Schedular();
schedular.add(task(100, 1), 1).then(res => console.log(res));
schedular.add(task(500, 2), 1).then(res => console.log(res));
schedular.add(task(300, 3), 0).then(res => console.log(res));
schedular.add(task(50, 4), 0).then(res => console.log(res));
// 輸出應(yīng)為4, 1, 3, 2