deno.land / x / masx200_leetcode_test@10.6.5 / sort-integers-by-the-power-value / cache.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export function cache<T extends (...args: any[]) => any>(fn: T): T { const store = new Map<string, ReturnType<T>>();
return ((...args) => { const key = args.length === 1 ? args[0] : JSON.stringify(args); const cached = store.get(key); if (store.has(key)) { return cached as ReturnType<T>; } const result = Reflect.apply(fn, undefined, args); store.set(key, result);
return result; }) as T;}
masx200_leetcode_test

Version Info

Tagged at
a year ago