Record the first internship interview - front-end engineering developer (ByteDance)

The interviewer is a very patient little brother, super gentle, and will guide me in some places, although I am very lazy (some time ago, the school was organizing the final exam, and on the first day after the exam, a young lady called to inform me The interview on the second day required a total of one day of preparation, alas, I must prepare well next time www), but the experience of the first interview is still good~

At the beginning, I was asked about my project experience, which project impressed me the most, the difficulty of the project, which project I learned the most, etc. It took a long time and I didn’t have time to see the blurred memory, but fortunately I was prepared before, but I The only thing that impressed me was the problems I encountered when I was working on the project. As for how to solve them, I was not impressed. Anyway, I just searched for blogs and read articles posted by others. Of course, I still need to have a full understanding of my project.

Then I was asked which technology stacks I am familiar with. Of course, the basis of the front end is html+css+js. I mainly tested this aspect and the code of es6 (but I have been reading the stereotyped essays in the interview when I was preparing, but I didn’t ask at all. Write The code is still very rusty, it took a long time)

The first question is the layout style of html+css. I used relative+absolute for the first time (at that time, the first thing that came to my mind was the whole, and I usually use it a lot for projects), and then the interviewer asked me Do you have any other ideas, and then I mentioned table layout, grid layout, and flex layout (I know these, but I haven’t really used them very much. I feel that relative+absolute in my project can be done occasionally with floating or something, but in the end It is the foundation, admit it and admit it)

The second question is an es6 question. Let me write the code running result. At the time, I only knew that the result of the third question was an object type object. I didn’t expect it to be in such a format.

let fun1 = x => x;
let fun2 = x => { x };
let fun3 = x => ({ x });
console.log(fun1(1));//1
console.log(fun2(1));//undefined
console.log(fun3(1));//{x:1}

The third question is about js. It is required to write a function. Each call will return a prime number. The next call will return the next prime number after this prime number. It is required that this function has no parameters and cannot use global variables (still empty-headed) ~ only half written)

//判断一个数是否为素数,如果是返回true,不是则返回false
function isPrimne(num){
    if(num==0||num==1) return false;
    for(let i = 2;i <= Math.sqrt(num);i++){
        if(num%i === 0){//这个数不是一个素数
            return false;
        }
    }
    return true;
}
function sushu(){
    let n = 0;
    return ()=>{
        while(1){
            n++;
            if(isPrimne(n)){
                return n;
            }
        }
    }
}
//将sushu返回出去的函数赋给一个变量
const getPrimne = sushu()
//调用新的函数
console.log(getPrimne())//2
console.log(getPrimne())//3
console.log(getPrimne())//5

In addition to this traditional closure method, there are also methods of using iterators and generator functions, which are also released here for future convenience~

//使用迭代器(但这里定义的这个prime应该是全局变量吧)
var prime = {}
prime[Symbol.iterator] = function () {
    let num= 1;
    return {
        next() {
            while (true) {
                num++;
                if (isPrimne(num)) {
                    return num;
                }
            }
        }
    }
}
var getPrime2 = prime[Symbol.iterator]().next;
console.log(getPrime());//2
console.log(getPrime());//3
// 生成器函数,但这个我运行并没有输出下一个素数,每次输出都是2
function* primeGenerator() {
    let prime = 1;
    while (true) {
        prime++;
        if (isPrimne(prime)) {
            yield prime;//yield:暂停函数
        }
    }
}
var getPrime3 = primeGenerator().next().value
console.log(getPrime3);//2
console.log(getPrime3);//2

The opportunity is very good, I didn't catch www, I must work harder next time!

Guess you like

Origin blog.csdn.net/qq_62070939/article/details/128106708