Skip to content

Instantly share code, notes, and snippets.

@zbinlin
Last active July 13, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbinlin/29440866963b5e4bcaf41fa030b40750 to your computer and use it in GitHub Desktop.
Save zbinlin/29440866963b5e4bcaf41fa030b40750 to your computer and use it in GitHub Desktop.
test

[基础] 实现一个简单的闭包。

function count() {
    var i = 0;
    return function _next_() {
        return i++;
    };
}

[基础] 实现获取斐波那契数列某个值方法。

function fibonacci(x) {
  var result = 0;
  // do staff begin
  if (x === 0 || x === 1) {
    result = 1;
  }
  for (let a = 1, b = 1, i = 2; i <= x; i++) {
    result = a + b;
    a = b;
    b = result;
  }
  // do staff end
  return result;
}

[基础] 实现某个阶乘阶乘函数方法。

function factorial(x) {
  var result = 0;
  // do staff begin
  result = 1;
  for (let i = 1; i <= x; i++) {
    result *= i;
  }
  // do staff end
  return result;
}

[js基础+算法] 将某个数组进行特定的排序。

先进行升序排序,然后把需要的 7, 5, 3 从数组里取出来,然后按要求合并。

[基础] 最新的 css 版本中,position ,几个值,以及其定位的时候相对参考坐标在哪里。

sticky,见 https://developer.mozilla.org/en-US/docs/Web/CSS/position#sticky

[基础] css 中 z-index 问题。(下面填空题答案很多,填充正确即可)

  1. #A { z-index: 50; }
  2. 无需改动
  3. ...

[基础] 下面绑定事件方式

  1. 方式一用的应该是事件冒泡的原理吧,方式二是直接绑定到元素上。
  2. 没做过测试,不好下结论。
  3. 方式一对于在 .btn 经常变化(元素增删)时,比较好点。

用 ES5 写一个 Animal 类及其两个不同实例。

function Animal(props) {
  this.name = props.name;
  // do staff begin
  this.say = function () {
  };
  // BTW,这种做并不好,弄脏了实例
  Animal.__instances__.push(this);
  // do staff end
}

// do staff begin
Animal.prototype.say = function () {
};
Animal.die = function (animal) {
  animal.die = true;
};
Animal.all = function () {
  return Animal.__instances__.filter(function _(animal) {
    return !animal.die;
  });
};
Animal.__instances__ = [];
// do staff end

var animalA = new Animal({ name: '小白鼠A' });
var animalB = new Animal({ name: '小白鼠B' });

上一题,改成 ES6 写法。

class Animal {
  constructor() {
    this.name = props.name;
    // do staff begin
    this.say = function () {
    };
    // BTW,这种做并不好,弄脏了实例
    Animal.__instances__.push(this);
    // do staff end
  }
  say() {
  }
  static die(animal) {
    animal.die = true;
  }
  static all() {
    return Animal.__instances__.filter(animal => !animal.die);
  }
}
Animal.__instances__ = [];
var animalA = new Animal({ name: '小白鼠A' });
var animalB = new Animal({ name: '小白鼠B' });

写一个匹配 url 中 pathname 的正则。

/https?:\/\/(?:[^\/]*)(\/(?:[^?#])*)/i

css 中 box-sizing 不同值及其作用。

border-box width, height 会包括 border-width 和 padding content-box width, height 不包括 border-width 和 padding

css 怎么计算选择器权重

https://www.w3.org/TR/CSS2/cascade.html#specificity

使用账号密码进行登录的时候,假设前端发送 username 、 password 到后端 api ,那后端的 api 是怎么校验这个账号及密码有效性的。

根据 username 在数据库中找出 hash 和 salt 字段,使用 password 和 salt 进行加密 hash 运算,得出的结果与取出来的 hash 字段进行比较。

[业务问题] 目前有一个登录业务(如果未注册账号,登录之后自动注册账号),直接手机号和短信验证码登录。

  1. 需要一个图形验证码接口、一个短信验证码接口
  2. 可以把对应的 token (或 session)设置失效时间

多层的 Promise 调用,如果中途某个 Promise 的 then 结果不符合预期,需要 reject 操作,应该怎么处理。

直接 throw 出一个异常,或 return 一个 reject 对象。

[算法问题] 有一个不重复的序列数组,经过N次轮转之后,找出最小值。(不知道N为多少,只知道最后的数组)

先判断第一个与最后一个数,如果第一个数小于最后一个数,则第一个数为最小值; 然后通过比较前一个与后一个数,如果前一个数大于后一个数,则后一个数为最小值。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment