找出字符串映射里的 bug

来自 哈希表
Node 24 进阶 6分钟 找出 2处问题

找出这个生成的字符串映射中的正确性缺陷。

JavaScript
class TinyMap {
  constructor() {
    this.buckets = Array(8);
  }
  index(key) {
    return [...key].reduce((sum, char) => sum + char.codePointAt(0), 0) % 8;
  }
  set(key, value) {
    this.buckets[this.index(key)] = { key, value };
  }
  get(key) {
    const entry = this.buckets[this.index(key)];
    return entry?.value;
  }
}
在试验场中打开
报告错误