deno.land / x / rambda@v9.1.1 / source / memoizeWith.spec.js

memoizeWith.spec.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { memoizeWith } from './memoizeWith.js'
test('calculates the value for a given input only once', () => { let ctr = 0 const fib = memoizeWith(x => x, n => { ctr += 1
return n < 2 ? n : fib(n - 2) + fib(n - 1) }) const result = fib(10) expect(result).toBe(55) expect(ctr).toBe(11)})
test('handles multiple parameters', () => { const f = memoizeWith(( a, b, c ) => a + b + c, ( a, b, c ) => a + ', ' + b + c)
expect(f( 'Hello', 'World', '!' )).toBe('Hello, World!') expect(f( 'Goodbye', 'Cruel World', '!!!' )).toBe('Goodbye, Cruel World!!!') expect(f( 'Hello', 'how are you', '?' )).toBe('Hello, how are you?') expect(f( 'Hello', 'World', '!' )).toBe('Hello, World!')})
rambda

Version Info

Tagged at
2 months ago