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
|
Rev | Line | |
---|
[d24f17c] | 1 | var _Set =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_Set.js");
|
---|
| 4 |
|
---|
| 5 | var _curry2 =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_curry2.js");
|
---|
| 8 |
|
---|
| 9 | var _dispatchable =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_dispatchable.js");
|
---|
| 12 |
|
---|
| 13 | var _xuniqBy =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./internal/_xuniqBy.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 function to
|
---|
| 19 | * each list element. Prefers the first item if the supplied function produces
|
---|
| 20 | * the same value on two items. [`R.equals`](#equals) is used for comparison.
|
---|
| 21 | *
|
---|
| 22 | * Acts as a transducer if a transformer is given in list position.
|
---|
| 23 | *
|
---|
| 24 | * @func
|
---|
| 25 | * @memberOf R
|
---|
| 26 | * @since v0.16.0
|
---|
| 27 | * @category List
|
---|
| 28 | * @sig (a -> b) -> [a] -> [a]
|
---|
| 29 | * @param {Function} fn A function used to produce a value to use during comparisons.
|
---|
| 30 | * @param {Array} list The array to consider.
|
---|
| 31 | * @return {Array} The list of unique items.
|
---|
| 32 | * @example
|
---|
| 33 | *
|
---|
| 34 | * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10]
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | var uniqBy =
|
---|
| 39 | /*#__PURE__*/
|
---|
| 40 | _curry2(
|
---|
| 41 | /*#__PURE__*/
|
---|
| 42 | _dispatchable([], _xuniqBy, function (fn, list) {
|
---|
| 43 | var set = new _Set();
|
---|
| 44 | var result = [];
|
---|
| 45 | var idx = 0;
|
---|
| 46 | var appliedItem, item;
|
---|
| 47 |
|
---|
| 48 | while (idx < list.length) {
|
---|
| 49 | item = list[idx];
|
---|
| 50 | appliedItem = fn(item);
|
---|
| 51 |
|
---|
| 52 | if (set.add(appliedItem)) {
|
---|
| 53 | result.push(item);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | idx += 1;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | return result;
|
---|
| 60 | }));
|
---|
| 61 |
|
---|
| 62 | module.exports = uniqBy; |
---|
Note:
See
TracBrowser
for help on using the repository browser.