source: node_modules/ramda/src/uniqWith.js@ d24f17c

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

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var _dispatchable =
6/*#__PURE__*/
7require("./internal/_dispatchable.js");
8
9var _includesWith =
10/*#__PURE__*/
11require("./internal/_includesWith.js");
12
13var _xuniqWith =
14/*#__PURE__*/
15require("./internal/_xuniqWith.js");
16/**
17 * Returns a new list containing only one copy of each element in the original
18 * list, based upon the value returned by applying the supplied predicate to
19 * two list elements. Prefers the first item if two items compare equal based
20 * on the predicate.
21 *
22 * Acts as a transducer if a transformer is given in list position.
23 *
24 * @func
25 * @memberOf R
26 * @since v0.2.0
27 * @category List
28 * @sig ((a, a) -> Boolean) -> [a] -> [a]
29 * @param {Function} pred A predicate used to test whether two items are equal.
30 * @param {Array} list The array to consider.
31 * @return {Array} The list of unique items.
32 * @example
33 *
34 * const strEq = R.eqBy(String);
35 * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
36 * R.uniqWith(strEq)([{}, {}]); //=> [{}]
37 * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
38 * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
39 */
40
41
42var uniqWith =
43/*#__PURE__*/
44_curry2(
45/*#__PURE__*/
46_dispatchable([], _xuniqWith, function (pred, list) {
47 var idx = 0;
48 var len = list.length;
49 var result = [];
50 var item;
51
52 while (idx < len) {
53 item = list[idx];
54
55 if (!_includesWith(pred, item, result)) {
56 result[result.length] = item;
57 }
58
59 idx += 1;
60 }
61
62 return result;
63}));
64
65module.exports = uniqWith;
Note: See TracBrowser for help on using the repository browser.