前段面试题(不定期更新)

一.CSS部分

1.实现不知宽高元素的垂直水平居中
2. CSS优先级算法如何计算
元素选择符: 1

class选择符: 10

id选择符:100

元素标签:1000

➤!important声明的样式优先级最高,如果冲突再进行计算。

➤如果优先级相同,则选择最后出现的样式。

➤继承得到的样式的优先级最低
3.雪碧图(精灵图)用法优点
4.flex布局

Javascript部分

1.打印结果

let food = ['apple', 'pear', 'banana', 'grap'];
for (let i=0;i<food.length;i++) {
  setTimeout(function(){
    console.log(food[i])
  },1)
}

2.打印结果

function test() {
  console.log(a);
  console.log(foo());
  let a = 1;
  function foo() {
    return 2;
  }
}
test()

3.打印结果

let fullName = 'aaa';
let obj = {
  fullName: 'bbb',
  prop: {
    fullName: 'ccc',
    getFullName: function() {
      return this.fullName;
    }
  }
}
var test = obj.prop.getFullName;
console.log(obj.prop.getFullName());
console.log(test())

4.编写代码实现如下功能
console.log(‘hello’.repeatify(3))
输出 hellohellohello

考点:自定义函数
参考:

String.prototype.repeatify = function (id) {
	let str = ""
	for (var i = 0; i < id; i++) {
	  str += this;
	}
	return str;
};
let strs = "hello";
console.log(strs.repeatify(3))

5.写一个函数实现
mul(f1(),f2(),f3()) 等价于 f3(f2(f1()))
实例:
// const add = x => x + 1;
// const multiply = (x, y) => x * y;
// const mix = x => x-10
// const newFn = composeFunctions(multiply, add);
// newFn(3, 4) // 返回 3

let add = function (x) {
  return x + 1
}
let mul = function (x, y) {
  return x * y
}
let mix = function (x) {
  return x-10
}
let newFn = composeFunctions(mul, add, mix)
function composeFunctions(...funcs) {
  return funcs.reduceRight((pre, next) => {
    return (...args) => pre(next(...args))
  })
}
console.log(newFn(3,4))

6.写一个函数完成如下输出
console.log(mul(2)(3)(4)) // 24
a.这种写法不推荐,虽然可以完成要求,但未答到考点

function mul (x) {
  return function (y) {
    return function (z) {
      return x*y*z
    }
  }
}

b.

function mul(x) {
  var sum = x
  var curried = function (y) {
    sum = sum * y
    return curried
  }
  curried.toString = function () {
    return sum
  }
  return curried
}

7.数组去重复

var arr = [1,2,1,3,3,4,8,5,4,3,2,1,3,5]

8.去掉数组中相邻的两个中重复的元素

var arr = [1,2,2,3,3,4,5,5]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值