1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _dispatchable =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_dispatchable");
|
8 |
|
9 | var _xdropRepeatsWith =
|
10 | /*#__PURE__*/
|
11 | require("./internal/_xdropRepeatsWith");
|
12 |
|
13 | var last =
|
14 | /*#__PURE__*/
|
15 | require("./last");
|
16 | /**
|
17 | * Returns a new list without any consecutively repeating elements. Equality is
|
18 | * determined by applying the supplied predicate to each pair of consecutive elements. The
|
19 | * first element in a series of equal elements will be preserved.
|
20 | *
|
21 | * Acts as a transducer if a transformer is given in list position.
|
22 | *
|
23 | * @func
|
24 | * @memberOf R
|
25 | * @since v0.14.0
|
26 | * @category List
|
27 | * @sig ((a, a) -> Boolean) -> [a] -> [a]
|
28 | * @param {Function} pred A predicate used to test whether two items are equal.
|
29 | * @param {Array} list The array to consider.
|
30 | * @return {Array} `list` without repeating elements.
|
31 | * @see R.transduce
|
32 | * @example
|
33 | *
|
34 | * const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
|
35 | * R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
|
36 | */
|
37 |
|
38 |
|
39 | var dropRepeatsWith =
|
40 | /*#__PURE__*/
|
41 | _curry2(
|
42 | /*#__PURE__*/
|
43 | _dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
|
44 | var result = [];
|
45 | var idx = 1;
|
46 | var len = list.length;
|
47 |
|
48 | if (len !== 0) {
|
49 | result[0] = list[0];
|
50 |
|
51 | while (idx < len) {
|
52 | if (!pred(last(result), list[idx])) {
|
53 | result[result.length] = list[idx];
|
54 | }
|
55 |
|
56 | idx += 1;
|
57 | }
|
58 | }
|
59 |
|
60 | return result;
|
61 | }));
|
62 |
|
63 | module.exports = dropRepeatsWith; |
\ | No newline at end of file |