forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreject.js
44 lines (35 loc) · 1.38 KB
/
reject.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var {Just, Nothing} = require('./shared/Maybe.js');
describe('reject', function() {
var even = function(x) {return x % 2 === 0;};
it('reduces an array to those not matching a filter', function() {
eq(R.reject(even, [1, 2, 3, 4, 5]), [1, 3, 5]);
});
it('returns an empty array if no element matches', function() {
eq(R.reject(function(x) { return x < 100; }, [1, 9, 99]), []);
});
it('returns an empty array if asked to filter an empty array', function() {
eq(R.reject(function(x) { return x > 100; }, []), []);
});
it('filters objects', function() {
eq(R.reject(R.equals(0), {}), {});
eq(R.reject(R.equals(0), {x: 0, y: 0, z: 0}), {});
eq(R.reject(R.equals(0), {x: 1, y: 0, z: 0}), {x: 1});
eq(R.reject(R.equals(0), {x: 1, y: 2, z: 0}), {x: 1, y: 2});
eq(R.reject(R.equals(0), {x: 1, y: 2, z: 3}), {x: 1, y: 2, z: 3});
});
it('dispatches to `filter` method', function() {
var m = new Just(42);
eq(R.filter(R.T, m), m);
eq(R.filter(R.F, m), Nothing);
eq(R.reject(R.T, m), Nothing);
eq(R.reject(R.F, m), m);
});
it('can act as a transducer', function() {
var input = [1, 2, 3, 4];
var expected = [1, 3];
eq(R.into([], R.reject(even), input), expected);
eq(R.transduce(R.reject(even), R.flip(R.append), [], input), expected);
});
});