Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 17x 17x 17x 17x 17x 17x 17x | /**
* Memoization technique that calls the callback once, subsequent calls
* simply returns the result of the first callback
*
* No arguments are passed to the callback
*
* @template {() => unknown} T
* @param {T} callback - callback to memoize
* @returns {() => ReturnType<T>} memoized function
*/
export function computeOnce (callback) {
let call = () => {
const result = /** @type {ReturnType<T>} */(callback())
call = () => result
return result
}
return () => call()
}
|