问题描述
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 (将#修改为@)