One caveat we should note is that it's possible to pass a key that doesn't exist (or has not been set
), so we should handle that by returning undefined
or None
if that's the case.
1get(key) {
2 let idx = this.hashStr(key);
3
4 if (!this._storage[idx]) {
5 return undefined;
6 }
7
8 for (let keyVal of this._storage[idx]) {
9 if (keyVal[0] === key) {
10 return keyVal[1];
11 }
12 }
13}