Skip to content

Instantly share code, notes, and snippets.

View AddyM's full-sized avatar

Aditya Mehra AddyM

  • American Express
  • Bangalore
View GitHub Profile
class HitCounter {
constructor(interval) {
this.interval = interval;
this.buckets = Array(60 / this.interval).fill(0);
this.bucketCleanerInterval = this.initBucketCleaner();
}
count() {
const bucket = this.getCurrentBucket();
return this.buckets[bucket] += 1;