1 | var _includesWith =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_includesWith");
|
4 |
|
5 | var _curry2 =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_curry2");
|
8 | /**
|
9 | * Returns a new list containing only one copy of each element in the original
|
10 | * list, based upon the value returned by applying the supplied predicate to
|
11 | * two list elements. Prefers the first item if two items compare equal based
|
12 | * on the predicate.
|
13 | *
|
14 | * @func
|
15 | * @memberOf R
|
16 | * @since v0.2.0
|
17 | * @category List
|
18 | * @sig ((a, a) -> Boolean) -> [a] -> [a]
|
19 | * @param {Function} pred A predicate used to test whether two items are equal.
|
20 | * @param {Array} list The array to consider.
|
21 | * @return {Array} The list of unique items.
|
22 | * @example
|
23 | *
|
24 | * const strEq = R.eqBy(String);
|
25 | * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
|
26 | * R.uniqWith(strEq)([{}, {}]); //=> [{}]
|
27 | * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
|
28 | * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
|
29 | */
|
30 |
|
31 |
|
32 | var uniqWith =
|
33 | /*#__PURE__*/
|
34 | _curry2(function uniqWith(pred, list) {
|
35 | var idx = 0;
|
36 | var len = list.length;
|
37 | var result = [];
|
38 | var item;
|
39 |
|
40 | while (idx < len) {
|
41 | item = list[idx];
|
42 |
|
43 | if (!_includesWith(pred, item, result)) {
|
44 | result[result.length] = item;
|
45 | }
|
46 |
|
47 | idx += 1;
|
48 | }
|
49 |
|
50 | return result;
|
51 | });
|
52 |
|
53 | module.exports = uniqWith; |
\ | No newline at end of file |