/** * Returns the same result for the same paramters (where the parameters are * considered the same if they have the same length and contain the same * ordered elements when elements are compared with `===` (e.g. objects are * compared *by reference*). * * @param f the function to cache * @param size the size (length) of the cache before older values will be * `shift`ed out into the nether */ function cache V>( f: F, size = 1): typeof f { const prevParamss: Parameters[] = []; const prevResults: V[] = []; return function(...params: Parameters): V { for (let i=0; i size) { prevParamss.shift(); prevResults.shift(); } //console.log('cache miss'); return result; } as F; } export { cache }