TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2653 3.78K
CHALLENGE

const cache = new Map();

function createHandler(id) {
const data = { id, value: new Array(1000).fill(id) };
cache.set(id, data);

return function(action) {
if (action === 'get') return data;
if (action === 'clear') cache.delete(id);
};
}

const handler1 = createHandler('user-1');
const handler2 = createHandler('user-2');

handler1('clear');
console.log(cache.size);
console.log(handler1('get').id);
More from @javascript
  1. Oct 1, 2026Post #3530
  2. Oct 1, 2026CHALLENGE class Counter { #count = 0; static #instances = 0; constructor() { Counter.#inst…
  3. Sep 30, 2026Post #3528
  4. Sep 30, 2026CHALLENGE const message = 'a😀bc'; const codePoints = [...message]; const combined = { raw…
  5. Sep 29, 2026Post #3526
  6. Sep 29, 2026CHALLENGE const order = []; order.push('start'); setTimeout(() => { order.push('timeout');…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →