Skip to content

Commit 358c437

Browse files
Create number_of_recent_calls.js
1 parent 7964b92 commit 358c437

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

number_of_recent_calls.js

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

0 commit comments

Comments
 (0)