pullAllWith.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. var basePullAll = require('./_basePullAll');
  2. /**
  3. * This method is like `_.pullAll` except that it accepts `comparator` which
  4. * is invoked to compare elements of `array` to `values`. The comparator is
  5. * invoked with two arguments: (arrVal, othVal).
  6. *
  7. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 4.6.0
  12. * @category Array
  13. * @param {Array} array The array to modify.
  14. * @param {Array} values The values to remove.
  15. * @param {Function} [comparator] The comparator invoked per element.
  16. * @returns {Array} Returns `array`.
  17. * @example
  18. *
  19. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  20. *
  21. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  22. * console.log(array);
  23. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  24. */
  25. function pullAllWith(array, values, comparator) {
  26. return (array && array.length && values && values.length)
  27. ? basePullAll(array, values, undefined, comparator)
  28. : array;
  29. }
  30. module.exports = pullAllWith;