【前端23校招面经】瓜子二手车一面
- 自我介绍
- 讲
git merge
和git rebase
的区别 - 多人用
git
同时开发, 讲一下线上发布流程, 如何保证团队成员安全 merge 代码 - 讲一下
CDN
回源策略 https
协议Vue
和React
区别cookie
/localStorage
/sessionStorage
区别- 浏览器缓存原理
- http 状态码
- 跨域方案
- 手写
Promise.all
function myAll(iterators) { const promises = Array.from(iterators); const values = []; return new Promise((resolve, reject) => { promises.forEach(p => { p.then((data, err) => { if (err) { reject(err); } values.push(data); if (values.length === promises.length) { resolve(values); } }); }); }); }
- 算法题: 查找两个数组的交集元素
function intersection<T>(arr1: T[], arr2: T[]): T[] { const shortArr = arr1.length < arr2.length ? arr1 : arr2; const longArr = shortArr === arr1 ? [...arr2] : [...arr1]; // 防止后续 splice 操作直接破坏传入的 arr 参数 const result = []; shortArr.forEach(item => { const index = longArr.findIndex(i => i === item); if (index !== -1) { result.push(item); } longArr.splice(index, 1); }); return result; } console.log(intersection([1, 2, 2, 1], [2, 2])); console.log(intersection([1, 2, 1], [2, 2]));
测试用例:
[1, 2, 2, 1], [2, 2] --> [2, 2] [1, 2, 1], [2, 2] --> [2]
#面经##校招##前端##瓜子二手车##面试#注意不能直接用 Set 莽干, 因为有些情况下不能去重