Moving '__tests__' To 'test'

This commit is contained in:
Damien Chazoule
2021-10-05 08:50:12 +02:00
parent c8fd5353ba
commit 8bce33d265
2 changed files with 3 additions and 9 deletions

View File

@ -4,24 +4,18 @@
* @returns
*/
export const memoize = (func) => {
// eslint-disable-next-line no-console
console.log(`Creating cache for function '${func.name}'`)
// Initializing new cache
const cache = {}
return (...args) => {
const [arg] = args
if (arg in cache) {
// eslint-disable-next-line no-console
console.log(`Reading cache with argument ${arg}`)
// Reading cache by argument
return cache[arg]
}
// eslint-disable-next-line no-console
console.log(`Updating cache with argument ${arg}`)
// Updating cache by argument
const result = func(arg)
cache[arg] = result
return result