File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ LRUCache.prototype.put = function(key, value) {
88
88
*/
89
89
const LRUCache = function ( capacity ) {
90
90
this . m = new Map ( )
91
- this . l = capacity
91
+ this . limit = capacity
92
92
} ;
93
93
94
94
/**
@@ -111,16 +111,14 @@ LRUCache.prototype.get = function(key) {
111
111
LRUCache . prototype . put = function ( key , value ) {
112
112
if ( this . m . has ( key ) ) {
113
113
this . m . delete ( key )
114
- this . m . set ( key , value )
115
114
} 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 )
119
118
}
120
- this . m . set ( key , value )
121
119
}
120
+ this . m . set ( key , value )
122
121
} ;
123
-
124
122
/**
125
123
* Your LRUCache object will be instantiated and called as such:
126
124
* var obj = new LRUCache(capacity)
You can’t perform that action at this time.
0 commit comments