forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniq.js
36 lines (28 loc) · 1.03 KB
/
uniq.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');
var {Just} = require('./shared/Maybe.js');
describe('uniq', function() {
it('returns a set from any array (i.e. purges duplicate elements)', function() {
var list = [1, 2, 3, 1, 2, 3, 1, 2, 3];
eq(R.uniq(list), [1, 2, 3]);
});
it('keeps elements from the left', function() {
eq(R.uniq([1, 2, 3, 4, 1]), [1, 2, 3, 4]);
});
it('returns an empty array for an empty array', function() {
eq(R.uniq([]), []);
});
it('has R.equals semantics', function() {
eq(R.uniq([-0, -0]).length, 1);
eq(R.uniq([0, -0]).length, 2);
eq(R.uniq([NaN, NaN]).length, 1);
eq(R.uniq([[1], [1]]).length, 1);
eq(R.uniq([new Just([42]), new Just([42])]).length, 1);
});
it('handles null and undefined elements', function() {
eq(R.uniq([void 0, null, void 0, null]), [void 0, null]);
});
it('uses reference equality for functions', function() {
eq(R.uniq([R.add, R.identity, R.add, R.identity, R.add, R.identity]).length, 2);
});
});