/**
* 字典
* 方法
* set(k,v) 向集合中添加元素
* hasKey(key) 查看某个元素是否存在于字典中
* remove(key) 删除某个键值对
* get(key) 获取key对应的value
* clear()
* size()
* isEmpty()
*/
class myMap {
constructor() {
this.item = {}
this.count = 0
}
hasKey() {
return items.hasOwnProperty(key);
}
set(key, value) {
this.count++
this.item[key] = value
}
remove(key) {
if(this.item.has(key)){
delete this.item[key]
this.count--
return true
}
else {
return false
}
}
get(key){
return this.item[key] || '不存在'
}
clear() {
this.item = {}
this.count = 0
}
isEmpty(){
return this.count === 0
}
}