阿里淘系前端暑期一面凉经
本来是周一,然后面试官说她出差约到了周四10.30,当时我就知道应该G了,太晚了阿里应该不缺人了。
上来四道题,28分钟....面试官说最好不要离开页面,会有提示(但是我要运行呀,还是在Vscode写的)
1. /* 问题:解析出url的每一个部份(包含协议,域名,端口,路径,query, hash)及每个query参数 */ 2 /* 问题:给定两个有序正整数数组,求他们的交集,例如[1,3,5,7,8]与[3,6,8,20,31]的交集为[3,8]。 */ /* 问题:实现方法f, 判断以下图结构中,是否存在闭环并打印出闭环上的节点 */ var graph = [ { src: 'g', dst: 'e' }, { src: 'a', dst: 'b' }, { src: 'f', dst: 'g' }, { src: 'e', dst: 'f' }, { src: 'c', dst: 'd' }, { src: 'b', dst: 'c' }, ]; /* 4. 简单实现一个事件订阅机制,具有监听on和触发emit以及取消监听off方法 /**
写了2和4,第一道说实话不记得正则没动,第3道写了一半到时间了,我说了下思路。确实写的慢了,按理说应该写完三个,第2题脑子抽了写了个复杂的。
// 第一题 function parseUrl(str) { const reg = /([a-z]+):\/\/([a-zA-Z0-9\.]+):?(\d+)?(.+(?=\?))\?([^#]*)#?(.*)/; const [s, domain, prot, line, query, hash] = reg.exec(str).slice(1); const qMap = {}; query.split('&').map(val => { const [a, b] = val.split('='); qMap[a] = b; }); return { s, domain, prot, line, qMap, hash }; } // 第二题不写了 // 第三题,有更好的写法可以在评论区交流 var graph = [ { src: 'g', dst: 'e' }, { src: 'a', dst: 'b' }, { src: 'f', dst: 'g' }, { src: 'e', dst: 'f' }, { src: 'c', dst: 'd' }, { src: 'b', dst: 'c' }, ]; function f() { const map = {}; graph.forEach(val => (map[val.src] = val.dst)); const line = []; let count = 0; let node = map[Object.keys(map)[0]]; while (count < graph.length) { if (line.includes(node)) { return line.slice(line.findIndex(val => val === node)); } line.push(node); node = map[node]; count++; } return null; } // 第四题,脑子也抽了,卡了一会 class EventEmitter { constructor() { this.eventList = {}; } emit(event, ...args) { const arr = this.eventList[event] || []; arr.forEach(fn => fn(...args)); } on(event, fn) { const arr = this.eventList[event] || []; arr.push(fn); this.eventList[event] = arr; } off(event, fn) { const arr = this.eventList[event] || []; arr = arr.filter(val => val !== fn); this.eventList[event] = arr; } }
后面聊了一下实习和项目,然后给我看了一道React的demo,说实话我没听明白要我干嘛,面试官问我有什么问题,有个地方写的很奇怪但是我没有说,我以为是她故意写的(现在回想起来我到底在干嘛?),然后不出意外的答错了。
问了React的流程,我答了render和commit,还有fiber的一些东西,我以为她会追问,结果没有。
部门技术栈也是react和类react,但是是偏C端的,我上个实习做的偏B端(但是我想做C端),可能面试官不太知道怎么问吧。
总体一个小时,问完挂了,面试时候也感觉到了,比较想吐槽的是,虽然这四个题不太难,但你让我30分钟写完确实有点...。第一题需要不断调(可能是我正则菜),但是网页的代码不好调试(因为四个题目都在,而且提示也不好)。
还是多谢阿里帮我补了一下正则。
#我的实习求职记录#