source: node_modules/ramda/es/dropRepeatsWith.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 _curry2 from "./internal/_curry2.js";
2import _dispatchable from "./internal/_dispatchable.js";
3import _xdropRepeatsWith from "./internal/_xdropRepeatsWith.js";
4import last from "./last.js";
5/**
6 * Returns a new list without any consecutively repeating elements. Equality is
7 * determined by applying the supplied predicate to each pair of consecutive elements. The
8 * first element in a series of equal elements will be preserved.
9 *
10 * Acts as a transducer if a transformer is given in list position.
11 *
12 * @func
13 * @memberOf R
14 * @since v0.14.0
15 * @category List
16 * @sig ((a, a) -> Boolean) -> [a] -> [a]
17 * @param {Function} pred A predicate used to test whether two items are equal.
18 * @param {Array} list The array to consider.
19 * @return {Array} `list` without repeating elements.
20 * @see R.transduce
21 * @example
22 *
23 * const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
24 * R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
25 */
26
27var dropRepeatsWith =
28/*#__PURE__*/
29_curry2(
30/*#__PURE__*/
31_dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
32 var result = [];
33 var idx = 1;
34 var len = list.length;
35
36 if (len !== 0) {
37 result[0] = list[0];
38
39 while (idx < len) {
40 if (!pred(last(result), list[idx])) {
41 result[result.length] = list[idx];
42 }
43
44 idx += 1;
45 }
46 }
47
48 return result;
49}));
50
51export default dropRepeatsWith;
Note: See TracBrowser for help on using the repository browser.