We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1aae183 commit 7855d50Copy full SHA for 7855d50
933-number-of-recent-calls.js
@@ -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