Design Authentication Manager LeetCode solution in JavaScript

1
// O(n)
2
var AuthenticationManager = function (timeToLive) {
3
this.ttl = timeToLive;
4
this.map = {};
5
};
6
AuthenticationManager.prototype.generate = function (tokenId, currentTime) {
7
this.map[tokenId] = currentTime + this.ttl;
8
};
9
AuthenticationManager.prototype.renew = function (tokenId, currentTime) {
10
let curr = this.map[tokenId];
11
if (curr > currentTime) {
12
this.generate(tokenId, currentTime);
13
}
14
};
15
AuthenticationManager.prototype.countUnexpiredTokens = function (currentTime) {
16
return Object.keys(this.map).filter((key) => this.map[key] > currentTime)
17
.length;
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0