1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _Set =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_Set");
|
8 | /**
|
9 | * Finds the set (i.e. no duplicates) of all elements in the first list not
|
10 | * contained in the second list. Objects and Arrays are compared in terms of
|
11 | * value equality, not reference equality.
|
12 | *
|
13 | * @func
|
14 | * @memberOf R
|
15 | * @since v0.1.0
|
16 | * @category Relation
|
17 | * @sig [*] -> [*] -> [*]
|
18 | * @param {Array} list1 The first list.
|
19 | * @param {Array} list2 The second list.
|
20 | * @return {Array} The elements in `list1` that are not in `list2`.
|
21 | * @see R.differenceWith, R.symmetricDifference, R.symmetricDifferenceWith, R.without
|
22 | * @example
|
23 | *
|
24 | * R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
|
25 | * R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]
|
26 | * R.difference([{a: 1}, {b: 2}], [{a: 1}, {c: 3}]) //=> [{b: 2}]
|
27 | */
|
28 |
|
29 |
|
30 | var difference =
|
31 | /*#__PURE__*/
|
32 | _curry2(function difference(first, second) {
|
33 | var out = [];
|
34 | var idx = 0;
|
35 | var firstLen = first.length;
|
36 | var secondLen = second.length;
|
37 | var toFilterOut = new _Set();
|
38 |
|
39 | for (var i = 0; i < secondLen; i += 1) {
|
40 | toFilterOut.add(second[i]);
|
41 | }
|
42 |
|
43 | while (idx < firstLen) {
|
44 | if (toFilterOut.add(first[idx])) {
|
45 | out[out.length] = first[idx];
|
46 | }
|
47 |
|
48 | idx += 1;
|
49 | }
|
50 |
|
51 | return out;
|
52 | });
|
53 |
|
54 | module.exports = difference; |
\ | No newline at end of file |