Mark As Completed Discussion

At this point, we have our building blocks, so let's go ahead and implement the set method. The method will:

  1. take the key passed
  2. run it through the hash function, and
  3. set the value in our storage at that particular index

Notice the way we're storing it as well: each index in this._storage (this._storage[idx]) is itself an array, thereby primitively solving for the collision problem.

1set(key, val) {
2  let idx = this.hashStr(key);
3
4  if (!this._storage[idx]) {
5    this._storage[idx] = [];
6  }
7
8  this._storage[idx].push([key, val]);
9}