-
-
Save digitalconceptvisuals/1f83527e5f245ec820c3bbe7793a490e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class to store frequency and recency of the key | |
class Frequency { | |
// Private fields | |
#frequency; // Number of times the key has been accessed | |
#recency; // Last timestamp of access | |
constructor(frequency = 1, recency = new Date()) { | |
this.#frequency = frequency; | |
this.#recency = recency.getTime() + recency.getMilliseconds(); | |
} | |
// Update frequency and recency | |
update = () => { | |
this.#frequency++; | |
let now = new Date(); | |
this.#recency = now.getTime() + now.getMilliseconds(); | |
} | |
get frequency() { return this.#frequency; } | |
get recency() { return this.#recency; } | |
toString = () => { | |
return `{ frequency: ${this.#frequency}, recency: ${this.#recency} }`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment