Skip to content

Commit 795e674

Browse files
authored
Update 146-lru-cache.js
1 parent d4cae51 commit 795e674

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

146-lru-cache.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ LRUCache.prototype.put = function(key, value) {
8888
*/
8989
const LRUCache = function(capacity) {
9090
this.m = new Map()
91-
this.l = capacity
91+
this.limit = capacity
9292
};
9393

9494
/**
@@ -111,16 +111,14 @@ LRUCache.prototype.get = function(key) {
111111
LRUCache.prototype.put = function(key, value) {
112112
if(this.m.has(key)) {
113113
this.m.delete(key)
114-
this.m.set(key, value)
115114
} else {
116-
if(this.m.size >= this.l) {
117-
const k = this.m.keys().next().value
118-
this.m.delete(k)
115+
if(this.m.size >= this.limit) {
116+
const first = this.m.keys().next().value
117+
this.m.delete(first)
119118
}
120-
this.m.set(key, value)
121119
}
120+
this.m.set(key, value)
122121
};
123-
124122
/**
125123
* Your LRUCache object will be instantiated and called as such:
126124
* var obj = new LRUCache(capacity)

0 commit comments

Comments
 (0)