pullAllBy.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. var baseIteratee = require('./_baseIteratee'),
  2. basePullAll = require('./_basePullAll');
  3. /**
  4. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  5. * invoked for each element of `array` and `values` to generate the criterion
  6. * by which they're compared. The iteratee is invoked with one argument: (value).
  7. *
  8. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 4.0.0
  13. * @category Array
  14. * @param {Array} array The array to modify.
  15. * @param {Array} values The values to remove.
  16. * @param {Array|Function|Object|string} [iteratee=_.identity]
  17. * The iteratee invoked per element.
  18. * @returns {Array} Returns `array`.
  19. * @example
  20. *
  21. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  22. *
  23. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  24. * console.log(array);
  25. * // => [{ 'x': 2 }]
  26. */
  27. function pullAllBy(array, values, iteratee) {
  28. return (array && array.length && values && values.length)
  29. ? basePullAll(array, values, baseIteratee(iteratee))
  30. : array;
  31. }
  32. module.exports = pullAllBy;