字节前端实习二面

1.介绍一下做过的项目
讲了一下,讲的不太好,面试官直接说算了,开始做题吧
2.  3道看题说输出: 原型链,this,promise
3.  3道编程题
    3-1 实现[['a', 'b'], ['n', 'm'], ['0', '1']] => ["an0", "an1", "am0", "am1", "bn0", "bn1", "bm0", "bm1"]
    很简单的 reduce 做就行了,当时想复杂了
    3-2 实现事件代理
    3-3 u.console("hello").settimeout(3000).console("world").settimeout(3000).console()
4. 输入url到页面渲染
全程 80min

求教,这个怎么实现:
u.console("hello").settimeout(3000).console("world").settimeout(3000).console()
首先输出hello,3s后输出world,再间隔3s,再输出#实习##面经##字节跳动##前端工程师#
全部评论
好家伙,80分钟太顶了
2
送花
回复
分享
发布于 2021-03-14 21:59
 function U (){         this.time = null;         this.totalTime = 0;         this.console = function(text){             if(this.time>=0){                 this.totalTime += this.time;                 setTimeout(()=>{                     console.log(text)                 },this.totalTime)             }else{                 console.log(text)             }             return this         }         this.settimeout = function(time){             this.time = time || 0;             return this         }        }     let u = new U();     u.console("hello").settimeout(3000).console("world").settimeout(3000).console()
1
送花
回复
分享
发布于 2021-03-16 09:23
秋招专场
校招火热招聘中
官网直投
var p =new Promise(resolve => {     console.log("hello")     setTimeout(()=>{         console.log("hello")         resolve()     },3000) }) p.then(()=>{     setTimeout(()=>{         console.log("hello")     },3000) })
1
送花
回复
分享
发布于 2021-03-17 12:01
直接做3道编程题?请问楼主还记得是哪些吗,难度怎么样
点赞
送花
回复
分享
发布于 2021-03-15 12:39
楼主面的是什么部门
点赞
送花
回复
分享
发布于 2021-03-16 14:16
想问下你,做算法题是用js吗还是其他的语言啊?
点赞
送花
回复
分享
发布于 2021-03-17 15:50
class U {   constructor() {     this.promise = Promise.resolve()   }   settimeout(time) {     this.promise = this.promise.then(       () =>         new Promise(resolve => {           setTimeout(() => {             resolve()           }, time)         })     )     return this   }   console() {     this.promise = this.promise.then(       () =>         new Promise(resolve => {           console.log(...arguments)           resolve()         })     )     return this   } } const u = new U()
点赞
送花
回复
分享
发布于 2021-03-19 16:49
点赞
送花
回复
分享
发布于 2021-03-19 17:32
同学,有没有兴趣投一下阿里巴巴大进口产品技术部,hc多多哈
点赞
送花
回复
分享
发布于 2021-04-01 16:26
个人实现: function uc() {     this.arr = []     this.event = []     this.time = 0     this.console = function (str) {         if (this.event.length == 0) console.log(str)         else {             setTimeout(() => {                 console.log(str)             }, this.event.shift())         }         return this     }     this.settimeout = function (time) {         this.time += time         this.event.push(this.time)         return this     } } let u = new uc() 使用累计计时,arr可以去掉,后续若要进阶一点需要使用到,比如说多个console后面加上settimeout
点赞
送花
回复
分享
发布于 2022-05-03 17:13
算法题套用回朔模板,实际上不需要回朔,递归就完了 let ad = function (arr) {     let fin = []     lop('', 0)     return fin     function lop(str, index) {         if (str.length == arr.length) {             fin.push(str)             return         }         for (let a of arr[index]) {             lop(str + a, index + 1)         }     } }
点赞
送花
回复
分享
发布于 2022-05-03 17:22
3-3应该主要考察Promise then的原理以及链式构造,以下是我的实现: class U{     constructor () {         this.promise = null     }     applyPromise (fn) {         if(!this.promise) {             this.promise = new Promise((resolve)=>fn(resolve))         }else{             this.promise = this.promise.then(()=>new Promise((resolve)=>fn(resolve)))         }     }     timeout(time) {         this.applyPromise((resolve)=>setTimeout(()=>resolve(),time))         return this     }     print() {         this.applyPromise((resolve)=>{             console.log(...arguments)             resolve()         })         return this     } } let u = new U() u.timeout(2000).print('haha&(17273)#39;).timeout(3000).print('jaja&(17274)#39;) 原理:通过函数构造以下结构 new Promise((resolve)=>{     console.log(1)     setTimeout(()=>resolve(),1000) }).then(()=>{     console.log(2)     return new Promise((resolve)=>setTimeout(()=>resolve(),2000)) }) .then(async ()=>{     console.log(3)     return new Promise((resolve)=>setTimeout(()=>resolve(),3000)) })
点赞
送花
回复
分享
发布于 2022-05-10 11:11

相关推荐

8 48 评论
分享
牛客网
牛客企业服务