mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Moving '__tests__' To 'test'
This commit is contained in:
@ -4,24 +4,18 @@
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const memoize = (func) => {
|
export const memoize = (func) => {
|
||||||
// eslint-disable-next-line no-console
|
// Initializing new cache
|
||||||
console.log(`Creating cache for function '${func.name}'`)
|
|
||||||
|
|
||||||
const cache = {}
|
const cache = {}
|
||||||
|
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
const [arg] = args
|
const [arg] = args
|
||||||
|
|
||||||
if (arg in cache) {
|
if (arg in cache) {
|
||||||
// eslint-disable-next-line no-console
|
// Reading cache by argument
|
||||||
console.log(`Reading cache with argument ${arg}`)
|
|
||||||
|
|
||||||
return cache[arg]
|
return cache[arg]
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// Updating cache by argument
|
||||||
console.log(`Updating cache with argument ${arg}`)
|
|
||||||
|
|
||||||
const result = func(arg)
|
const result = func(arg)
|
||||||
cache[arg] = result
|
cache[arg] = result
|
||||||
return result
|
return result
|
||||||
|
Reference in New Issue
Block a user