如何解决无法从 hashMap 读取未定义的属性“长度”
Cannot read property 'length' of undefined
这是我的代码
class HashMap{
table = new Array(17);
get(key){
let idx = hashfun(key,this.table.length)
return this.table[idx]
}
set(key,value){
let idx = hashfun(key,this.table.length)
return this.table[idx]
}
}
function hashfun(s,arrlen){
console.log("***",s)
let hash = 17;
for(let i=0; i< s.length; i++){
hash = (13 * hash * s.charCodeAt(i)) % arrlen;
}
return hash
}
let ht = new HashMap();
ht.set("trying")
ht.get()
我正在尝试将键转换为 Int 并将键分配给索引。如果我做错了什么,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。