console.clear()
class LRUCache{
constructor(length){
this.length = length
this.data = {}
}
set(key, value){
if(this.data[key]){
delete this.data[key]
}
this.data[key] = value
const keys = Object.keys(this.data)
if(keys.length > this.length){
delete this.data[keys[0]]
}
console.log('set', this.data)
}
get(key){
const value = this.data[key]
delete this.data[key]
this.data[key] = value
console.log('get', this.data)
return value
}
}
var lru = new LRUCache(3)
lru.set(1,1)
lru.set(2,2)
lru.set(3,3)
console