CVTE前端一面面经
1. 自我介绍
2. 问实习经历,觉得最困难的是什么
3. 问场景题
现在有三个场景,你怎么分析,怎么排查问题
a. 类似与百度图片,图片加载不出来
(前端问题、后台问题、cdn、浏览器版本过低、网络问题)
b. 页面出现白屏
c. 做一个无限加载列表,下滑的时候会有卡顿,查看大图的时候左滑右滑也有卡顿
4. 在一个页面中html中,背景颜色是红色,有很多img,但是src是比较大的资源,在网页打开的一瞬间,所看到的变化都有什么
5. 目前存在一批任务,这些任务数据结构如下,任务默认不存在循环依赖。要求实现一个函数,该函数可以计算出一批任务的最长耗时,并给出最长耗时的任务执行顺序
interface Task { // 任务id id: string; // 任务执行耗时 cost: number; // 前置任务id,可选 dep?: string; } // 实例任务列表 const tasks: Task[] = [ { id: '1', cost: 100 }, { id: '2', cost: 100, dep: '4' }, { id: '4', cost: 100, dep: '3' }, { id: '3', cost: 100 }, ]; // 输出 300 3 4 2
// interface Task { // // 任务id // id: string; // // 任务执行耗时 // cost: number; // // 前置任务id,可选 // dep?: string; // } // // 实例任务列表 // const tasks: Task[] = [ // { id: '1', cost: 100 }, // { id: '2', cost: 100, dep: '4' }, // { id: '4', cost: 100, dep: '3' }, // { id: '3', cost: 100 }, // ]; // 输出 // 300 // 3 4 2 const tasks = [ { id: '1', cost: 100 }, { id: '2', cost: 100, dep: '4' }, { id: '4', cost: 100, dep: '3' }, { id: '3', cost: 100 }, ]; function time(tasks) { let max = 0; let maxArr = []; let arr = [0]; let cost = [0]; for(i = 0;i < tasks.length; i++){ if(tasks[i]?.dep){ arr[tasks[i]?.id] = tasks[i].dep; }else{ arr[tasks[i]?.id] = 0; } cost[tasks[i]?.id] = tasks[i].cost; } // console.log(arr,cost); for(i = 1;i <= tasks.length; i++){ if(arr[i] != 0){ // let sum = tasks[i-1].cost; // let sumArr = [i]; let sum = 0; let sumArr = []; let j = i; while(true){ sum += cost[j]; sumArr.push(j) j = arr[j] if(j==0) break; } if(sum > max){ max = sum; maxArr = sumArr; } } } return [max, maxArr]; } console.log(time(tasks));