forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropRepeatsWith.js
36 lines (29 loc) · 1007 Bytes
/
dropRepeatsWith.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('dropRepeatsWith', function() {
var objs = [
{i: 1}, {i: 2}, {i: 3}, {i: 4}, {i: 5}, {i: 3}
];
var objs2 = [
{i: 1}, {i: 1}, {i: 1}, {i: 2}, {i: 3},
{i: 3}, {i: 4}, {i: 4}, {i: 5}, {i: 3}
];
var eqI = (a, b) => a.i === b.i;
it('removes repeated elements based on predicate', function() {
eq(R.dropRepeatsWith(eqI, objs2), objs);
eq(R.dropRepeatsWith(eqI, objs), objs);
});
it('keeps elements from the left', function() {
eq(
R.dropRepeatsWith(eqI, [{i: 1, n: 1}, {i: 1, n: 2}, {i: 1, n: 3}, {i: 4, n: 1}, {i: 4, n: 2}]),
[{i: 1, n: 1}, {i: 4, n: 1}]
);
});
it('returns an empty array for an empty array', function() {
eq(R.dropRepeatsWith(eqI, []), []);
});
it('can act as a transducer', function() {
eq(R.into([], R.dropRepeatsWith(eqI), objs2), objs);
eq(R.transduce(R.dropRepeatsWith(eqI), R.flip(R.append), [], objs2), objs);
});
});