UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

44 lines (43 loc) 1.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.differenceWith = void 0; const baseDifference_1 = __importDefault(require("./.internal/baseDifference")); const baseFlatten_1 = __importDefault(require("./.internal/baseFlatten")); const isArrayLikeObject_1 = __importDefault(require("./isArrayLikeObject")); const last_1 = __importDefault(require("./last")); /** * This method is like `difference` except that it accepts `comparator` * which is invoked to compare elements of `array` to `values`. The order and * references of result values are determined by the first array. The comparator * is invoked with two arguments: (arrVal, othVal). * * **Note:** Unlike `pullAllWith`, this method returns a new array. * * @since 5.9.0 * @category Array * @param array The array to inspect. * @param values The values to exclude. * @returns Returns the new array of filtered values. * @example * * ```js * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] * * differenceWith(objects, [{ 'x': 1, 'y': 2 }], isEqual) * // => [{ 'x': 2, 'y': 1 }] * ``` */ function differenceWith(array, ...values) { let comparator = (0, last_1.default)(values); if ((0, isArrayLikeObject_1.default)(comparator)) { comparator = undefined; } return (0, isArrayLikeObject_1.default)(array) ? (0, baseDifference_1.default)(array, (0, baseFlatten_1.default)(values, 1, isArrayLikeObject_1.default, true), undefined, comparator) : []; } exports.differenceWith = differenceWith; exports.default = differenceWith;