Skip to content

Instantly share code, notes, and snippets.

@digitalconceptvisuals
Last active July 29, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalconceptvisuals/1f83527e5f245ec820c3bbe7793a490e to your computer and use it in GitHub Desktop.
Save digitalconceptvisuals/1f83527e5f245ec820c3bbe7793a490e to your computer and use it in GitHub Desktop.
// 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