Skip to content

Commit 7855d50

Browse files
authored
Create 933-number-of-recent-calls.js
1 parent 1aae183 commit 7855d50

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

933-number-of-recent-calls.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const RecentCounter = function() {
2+
this.pings = [];
3+
};
4+
5+
/**
6+
* @param {number} t
7+
* @return {number}
8+
*/
9+
RecentCounter.prototype.ping = function(t) {
10+
if (t === null) return null;
11+
if (t > 3000) {
12+
let delta = t - 3000;
13+
while (this.pings.length > 0 && this.pings[0] < delta) {
14+
this.pings.shift();
15+
}
16+
}
17+
18+
this.pings.push(t);
19+
return this.pings.length;
20+
};
21+
22+
/**
23+
* Your RecentCounter object will be instantiated and called as such:
24+
* var obj = new RecentCounter()
25+
* var param_1 = obj.ping(t)
26+
*/

0 commit comments

Comments
 (0)