提前批字节抖音国际

项目经历 实习经历略过
http1.1 http2 长链接 多路复用之类
问了一些有关后端的,比如C#会不会 用过spring node会不会(最后问面试官说他们那有很多全栈)
promise的简单问题
很多印象不深了,唯一一个没有印象的题是:

window.onload和DOMContentLoaded的区别

一、何时触发这两个事件?

1、当 onload 事件触发时,页面上所有的DOM样式表脚本图片flash都已经加载完成了。

2、当 DOMContentLoaded 事件触发时,仅当DOM加载完成,不包括样式表,图片,flash。

二、为什么要区分

开发中我们经常需要给一些元素的事件绑定处理函数。但问题是,如果那个元素还没有加载到页面上,但是绑定事件已经执行完了,是没有效果的。

这两个事件大致就是用来避免这样一种情况,将绑定的函数放在这两个事件的回调中,保证能在页面的某些元素加载完毕之后再绑定事件的函数。

当然DOMContentLoaded机制更加合理,因为我们可以容忍图片,flash延迟加载,却不可以容忍看见内容后页面不可交互。


两个手写题:
1. 双栈实现队列
Suppose you have a stack, which has only follow interface:
    
    
    
		
        class Stack {     
    
        push(element) { /* add element to stack */ }     
    
        peek() { /* get the top element */ }     
    
        pop() { /* remove the top element */}     
    
        size() { /* count of elements */}     
    
        }     
Could you implement a Queue by using only above Stack?
Note:you can only use Stack as provided, Array should be avoided for the purpose of practicing.

class Queue {
    constructor(){
        this.stack1 = new Stack();
        this.stack2= new Stack();
    }

  enqueue(element) { 
    stack1.push(element);
  }
  peek() { 
    if(stack2.size()===0) this.tranform();
    return stack2.peek();
  }
  size() { 
    return this.stack1.size()+this.stack2.size();
  }
  dequeue() {
    if(stack2.size()===0) this.tranform();
    return stack2.pop();
  }
  transform(){
      if(stack1.size()===0) throw Error('error')
        while(stack1.size()>0) {
            stack2.push(stack1.pop());
        }
    }
  }
}
2.树的高度

get DOM tree height

Height of a tree is the maximum depth from root node. Empty root node have a height of 0.
If given DOM tree, can you create a function to get the height of it?
For the DOM tree below, we have a height of 4.
    
   
     
		
        <div>   
    
        <div>     
    
        <p>     
    
        <button>Hello</button>     
    
        </p>     
    
        </div>     
    
        <p>     
    
        <span>World!</span>     
    
        </p>     
    
        </div>     

/**
 * @param {HTMLElement | null} tree
 * @return {number}
 */
function getHeight(tree) {
    if(tree===null) return 0;
    if(!tree.children) return 1;
    let childMaxH=0;
    tree.children.map((item)=>{
        childMaxH=Math.max(childMaxH, getHeight(item));
    })
    return 1+childMaxH;
}

function g







#字节跳动内推提前批##字节跳动##校招##面经#
全部评论

相关推荐

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