Icard/angular-clarity-master(work.../node_modules/ramda/es/dropRepeatsWith.js

51 lines
1.4 KiB
JavaScript

import _curry2 from "./internal/_curry2.js";
import _dispatchable from "./internal/_dispatchable.js";
import _xdropRepeatsWith from "./internal/_xdropRepeatsWith.js";
import last from "./last.js";
/**
* Returns a new list without any consecutively repeating elements. Equality is
* determined by applying the supplied predicate to each pair of consecutive elements. The
* first element in a series of equal elements will be preserved.
*
* Acts as a transducer if a transformer is given in list position.
*
* @func
* @memberOf R
* @since v0.14.0
* @category List
* @sig ((a, a) -> Boolean) -> [a] -> [a]
* @param {Function} pred A predicate used to test whether two items are equal.
* @param {Array} list The array to consider.
* @return {Array} `list` without repeating elements.
* @see R.transduce
* @example
*
* const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
* R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
*/
var dropRepeatsWith =
/*#__PURE__*/
_curry2(
/*#__PURE__*/
_dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
var result = [];
var idx = 1;
var len = list.length;
if (len !== 0) {
result[0] = list[0];
while (idx < len) {
if (!pred(last(result), list[idx])) {
result[result.length] = list[idx];
}
idx += 1;
}
}
return result;
}));
export default dropRepeatsWith;