前端面试题

前端面试题

从进公司到现在,公司的那份前端面试题好像就没变过,一些题目可能有些过时或者比较偏题,然后每次有同行来面试,就是看着简历一顿尬聊,所以在此个人为公司整理出一份前端面试题。

1. 给定一个字符串var str = ‘abcabcefbbd’,实现以下需求:

(1)求字符a出现的次数
(2)求出现次数最多的字符,出现的次数是多少

2. 说出以下代码输出多少?

1
2
3
4
5
6
7
8
9
10
11
12
13
var c = 0
function print(){
console.log(window.c)
}
function plus(){
setTimeout(function(){
c+=1
}, 1000)
}
plus()
print()

3. 给定一个数组var arr = [1,1,2,3,4,4,5],实现数组去重,输入[1,2,3,4,5]

4. 实现一个千位符分割方法,例如3899000001 => 3,899,000,001。

5. 说出以下题目依次输出什么,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function person(describe, name) {
this.describe = describe
this.name = name
return this
}
var Person = new person('狗才','这是描述3')
console.log(describe) //?
console.log(name) //?
console.log(Person.describe) //?
console.log(Person.name) //?
var describe = '这是描述1'
var name = '狗黄'
person('狗朱', '这是描述2')
console.log(window.describe) //?
console.log(window.name) //?
person.call()
console.log(describe) //?
console.log(name) //?

6. 实现一个拍平数组的函数,完全以下需求,代码如下:

1
2
3
4
5
6
var source = ['first',['second',['third',['fourth']]],'fifth',['sixth']]
function beatArr(arr) {
// TODO
}
console.log(beatArr(source)) //['first', 'second','third','fourth','fifth','sixth']

7. 如何不借助第三个变量,转换两个整数的值,例如:

1
2
3
var a = 10,b = 20;
// TODO
console.log(a,b) //20, 10

8. 请描述下call、apply、bind的作用和区别,并且有哪些常用的场景?

9. 实现currying函数,完成以下需求,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function sum(a, b, c) {
return a + b + c;
}
function currying(fn) {
// TODO
}
var curry = currying(sum)
console.log(currying(sum,1,2,3)) //6
console.log(curry(1)(2)(3)) //6
console.log(curry(1,2)(3)) //6
console.log(curry()(1)(2)(3)) //6
console.log(curry(1,2,3)) //6

10. 请用flex布局实现如下页面: