forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifference.js
43 lines (35 loc) · 1.3 KB
/
difference.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var {Just} = require('./shared/Maybe.js');
describe('difference', function() {
var M = [1, 2, 3, 4];
var M2 = [1, 2, 3, 4, 1, 2, 3, 4];
var N = [3, 4, 5, 6];
var N2 = [3, 3, 4, 4, 5, 5, 6, 6];
var Z = [3, 4, 5, 6, 10];
var Z2 = [1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8];
it('finds the set of all elements in the first list not contained in the second', function() {
eq(R.difference(M, N), [1, 2]);
});
it('does not allow duplicates in the output even if the input lists had duplicates', function() {
eq(R.difference(M2, N2), [1, 2]);
});
it('has R.equals semantics', function() {
eq(R.difference([0], [-0]).length, 1);
eq(R.difference([-0], [0]).length, 1);
eq(R.difference([NaN], [NaN]).length, 0);
eq(R.difference([new Just([42])], [new Just([42])]).length, 0);
});
it('works for arrays of different lengths', function() {
eq(R.difference(Z, Z2), [10]);
eq(R.difference(Z2, Z), [1, 2, 7, 8]);
});
it('will not create a "sparse" array', function() {
eq(R.difference(M2, [3]).length, 3);
});
it('returns an empty array if there are no different elements', function() {
eq(R.difference(M2, M), []);
eq(R.difference(M, M2), []);
eq(R.difference([], M2), []);
});
});