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

partition.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { partition } from './partition.js'
test('with array', () => { const predicate = x => x > 2 const list = [ 1, 2, 3, 4 ]
const result = partition(predicate, list) const expectedResult = [ [ 3, 4 ], [ 1, 2 ], ]
expect(result).toEqual(expectedResult)})
test('with object', () => { const predicate = (value, prop) => { expect(typeof prop).toBe('string')
return value > 2 } const hash = { a : 1, b : 2, c : 3, d : 4, }
const result = partition(predicate)(hash) const expectedResult = [ { c : 3, d : 4, }, { a : 1, b : 2, }, ]
expect(result).toEqual(expectedResult)})
test('readme example', () => { const list = [ 1, 2, 3 ] const obj = { a : 1, b : 2, c : 3, } const predicate = x => x > 2
const result = [ partition(predicate, list), partition(predicate, obj) ] const expected = [ [ [ 3 ], [ 1, 2 ] ], [ { c : 3 }, { a : 1, b : 2, }, ], ] expect(result).toEqual(expected)})
rambda

Version Info

Tagged at
7 months ago