forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropRepeatsBy.js
38 lines (31 loc) · 977 Bytes
/
dropRepeatsBy.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('dropRepeatsBy', 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 fn = ({ i }) => ({ i: Math.abs(i) });
it('removes repeated elements based on predicate', function() {
eq(R.dropRepeatsBy(fn, objs2), objs);
eq(R.dropRepeatsBy(fn, objs), objs);
});
it('keeps elements from the left', function() {
eq(
R.dropRepeatsBy(
({ n, ...rest }) => ({ ...rest }),
[{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.dropRepeatsBy(fn, []), []);
});
it('can act as a transducer', function() {
eq(R.into([], R.dropRepeatsBy(fn), objs2), objs);
});
});