-
-
Save digitalconceptvisuals/0db32ebc7e55423b05c989d3dbbf23f2 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
let number = 10; | |
let smartPrime = memoize(isPrime, mfu = 3); | |
smartPrime(1); | |
smartPrime(2); | |
smartPrime(2); // MFU | |
smartPrime(1); // MFU | |
smartPrime(3); // MRU | |
smartPrime(4); | |
console.log(smartPrime.cache); | |
/* Output | |
Initialized map with size=3 | |
Updated { 1 => { frequency: 1, recency: 1596064558140 } } | |
Updated { 2 => { frequency: 1, recency: 1596064558148 } } | |
Updated { 3 => { frequency: 1, recency: 1596064558148 } } | |
Updated { 2 => { frequency: 2, recency: 1596064558150 } } | |
Updated { 1 => { frequency: 2, recency: 1596064558150 } } | |
Updated { 4 => { frequency: 1, recency: 1596064558150 } } | |
Resizing map: 4 > 3 | |
Deleting { 3 => { frequency: 1, recency: 1596064558148 } | |
MFUMap(3) [Map] { '1' => false, '2' => true, '4' => false } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment