@newdash/newdash
Version:
javascript/typescript utility library
37 lines (36 loc) • 1.46 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.xorWith = void 0;
const baseXor_1 = __importDefault(require("./.internal/baseXor"));
const isArrayLikeObject_1 = __importDefault(require("./isArrayLikeObject"));
/**
* This method is like `xor` except that it accepts `comparator` which is
* invoked to compare elements of `arrays`. The order of result values is
* determined by the order they occur in the arrays. The comparator is invoked
* with two arguments: (arrVal, othVal).
*
* @since 5.7.0
* @category Array
* @param arrays The arrays to inspect.
* @param comparator The comparator invoked per element.
* @returns Returns the new array of filtered values.
* @see [[difference]], [[union]], [[unionBy]], [[unionWith]], [[without]], [[xor]], [[xorBy]]
* @example
*
* ```js
* const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
* const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]
*
* xorWith(objects, others, isEqual)
* // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
* ```
*/
function xorWith(comparator, ...arrays) {
comparator = typeof comparator === "function" ? comparator : undefined;
return (0, baseXor_1.default)(arrays.filter(isArrayLikeObject_1.default), undefined, comparator);
}
exports.xorWith = xorWith;
exports.default = xorWith;