字节跳动前端二面

本人一年半工作经验。面的是麦哲伦。

  1. 自我介绍
  2. 问了一下项目的内容,你觉得你这段工作期间最好的产出是什么?
  3. 然后问了一下项目细节。
  4. 怎么避免React组件的重复渲染。(shouldComponentUpdate,React.memo,useMemo,useCallback)
  5. 怎么避免Vue组件的重复渲染(v-once,keep-alive,避免频繁的修改Vue的data,computed属性缓存)
  6. Vue nextTick的原理能说一下吗?(巴拉巴拉)
  7. webpack常用配置项是什么?(entry, output, module.rules, optimize.splitChunks,mode)
  8. 如果要使用less,那么webpack的css loader怎么配置?(style-loader, css-loader, less-loader,生产环境是minicssextract.loader,css-loader, less-loader)
  9. 好,我们来做题吧
// 请实现一个调度器,这个调度器保证任务的并发数为2
class schedular {
  // task是一个函数,会返回一个promise,add也会返回一个promise,add的promise根据task的promise状态改变
  add (task) {
  }
}

const task = (duration, order) => new Promise((resolve) => {
  setTimeout(() => {
    resolve(order);
  }, duration);
});

// 开始测试
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));
// 结果应该为1, 3, 4, 2

根据上面的题目,修改schedular的add函数为下面的代码,然后根据优先级priority进行调度工作。优先级越小越优先。

// add函数变更
  add (task, priority) {
    
  }

// 测试代码变更
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));
// 输出应为4, 1, 3, 2

你可能感兴趣的:(字节跳动前端二面)