1 | var _includesWith =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_includesWith.js");
|
---|
4 |
|
---|
5 | var _curry3 =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_curry3.js");
|
---|
8 | /**
|
---|
9 | * Finds the set (i.e. no duplicates) of all elements in the first list not
|
---|
10 | * contained in the second list. Duplication is determined according to the
|
---|
11 | * value returned by applying the supplied predicate to two list elements.
|
---|
12 | *
|
---|
13 | * @func
|
---|
14 | * @memberOf R
|
---|
15 | * @since v0.1.0
|
---|
16 | * @category Relation
|
---|
17 | * @sig ((a, a) -> Boolean) -> [a] -> [a] -> [a]
|
---|
18 | * @param {Function} pred A predicate used to test whether two items are equal.
|
---|
19 | * @param {Array} list1 The first list.
|
---|
20 | * @param {Array} list2 The second list.
|
---|
21 | * @return {Array} The elements in `list1` that are not in `list2`.
|
---|
22 | * @see R.difference, R.symmetricDifference, R.symmetricDifferenceWith
|
---|
23 | * @example
|
---|
24 | *
|
---|
25 | * const cmp = (x, y) => x.a === y.a;
|
---|
26 | * const l1 = [{a: 1}, {a: 2}, {a: 3}];
|
---|
27 | * const l2 = [{a: 3}, {a: 4}];
|
---|
28 | * R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}]
|
---|
29 | *
|
---|
30 | * R.differenceWith(R.equals, [1, 2, 3, 3, 3], []); //=> [1, 2, 3]
|
---|
31 | * R.differenceWith(R.equals, [1, 2, 3, 3, 3], [1]); //=> [2, 3]
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | var differenceWith =
|
---|
36 | /*#__PURE__*/
|
---|
37 | _curry3(function differenceWith(pred, first, second) {
|
---|
38 | var out = [];
|
---|
39 | var idx = 0;
|
---|
40 | var firstLen = first.length;
|
---|
41 |
|
---|
42 | while (idx < firstLen) {
|
---|
43 | if (!_includesWith(pred, first[idx], second) && !_includesWith(pred, first[idx], out)) {
|
---|
44 | out.push(first[idx]);
|
---|
45 | }
|
---|
46 |
|
---|
47 | idx += 1;
|
---|
48 | }
|
---|
49 |
|
---|
50 | return out;
|
---|
51 | });
|
---|
52 |
|
---|
53 | module.exports = differenceWith; |
---|