source: node_modules/ramda/es/differenceWith.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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