剧场模式
首页软件其他有趣,好玩的软件世界

2020 年为什么要学 TypeScript?我用代码告诉你!

求知小风 · 元婴发布于新课程
0

https://www.qiuzhi99.com/playlists/typescript.html

https://www.qiuzhi99.com/playlists/ts-restful-api.html

https://www.zhihu.com/question/308844713/answer/957733913

https://nestjs.com/

https://angular.io/

https://cn.vuejs.org/index.html

https://github.com/reduxjs/redux

相关的源码:

function hashStringToInt(s, tableSize) {
  let hash = 17;

  for (let i = 0; i < s.length; i++) {
    hash = (13 * hash * s.charCodeAt(i)) % tableSize;
  }

  return hash;
}

class HashTable {
  table = new Array(3333);
  numItems = 0;

  resize = () => {
    const newTable = new Array(this.table.length * 2);

    this.table.forEach(item => {
      if (item) {
        const idx = hashStringToInt(item[0], newTable.length);
        newTable[idx] = item;
      }
    });

    this.table = newTable;
  };

  getItem = key => {
    const idx = hashStringToInt(key, this.table.length);

    if (!this.table[idx]) {
      return null;
    }

    return this.table[idx][1];
  };

  setItem = (key, val) => {
    this.numItems++;
    const loadFactor = this.numItems / this.table.length;

    if (loadFactor > 0.8) {
      this.resize();
    }

    const idx = hashStringToInt(key, this.table.length);
    this.table[idx] = [key, val];
  };
}

const myTable = new HashTable();
myTable.setItem("firstName", "bob");
myTable.setItem("f", "bob1");
myTable.setItem("firstNafe", "bob2");
myTable.setItem("firstNafe", "bob3");
console.log(myTable.getItem("firstName"));
console.log(myTable.getItem("f"));
console.log(myTable.getItem("firstNafe"));

https://github.com/hfpp2012/qiuzhi99.ts.permissions.mocha

1 条回复

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 关注我们 | 在线学员:119

Top