字典
字典跟集合类似,但字典是以[键,值]的形式存储元素
//在字典中理想的情况是用字符串作为键名,值可以是任何类型,但JS的限制,不能保证键一定是字符串,所以需要把键名传入的对象转为字符串
class defaultToString(item){
if(item ==null){
return "NULL"
}else if(item ===underfined){
return "UNDERFINED"
}eles if(typeof item ==="string"||item instanceof String){
return `${item}`
}
return item.toString
}
class Dictionary{
constructor(toStrFn = defaultToString){
this.toStrFn = toStrFn
this.table = {}
}
}
散列表
散列表的作用在于给定一个键值,通过键值返回表中的地址中的具体数值