MCPcopy
hub / github.com/TheAlgorithms/JavaScript / fibonacciCache

Function fibonacciCache

Cache/test/cacheTest.js:8–26  ·  view source on GitHub ↗
(n, cache = null)

Source from the content-addressed store, hash-verified

6 * @returns {number}
7 */
8export const fibonacciCache = (n, cache = null) => {
9 if (cache) {
10 const value = cache.get(n)
11
12 if (value !== null) {
13 return value
14 }
15 }
16
17 if (n === 1 || n === 2) {
18 return 1
19 }
20
21 const result = fibonacciCache(n - 1, cache) + fibonacciCache(n - 2, cache)
22
23 cache && cache.set(n, result)
24
25 return result
26}
27
28/**
29 * @title implementation of union function

Callers 2

LFUCache.test.jsFile · 0.90
LRUCache.test.jsFile · 0.90

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected