_basePullAll.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var arrayMap = require('./_arrayMap'),
  2. baseIndexOf = require('./_baseIndexOf'),
  3. baseIndexOfWith = require('./_baseIndexOfWith'),
  4. baseUnary = require('./_baseUnary'),
  5. copyArray = require('./_copyArray');
  6. /** Used for built-in method references. */
  7. var arrayProto = Array.prototype;
  8. /** Built-in value references. */
  9. var splice = arrayProto.splice;
  10. /**
  11. * The base implementation of `_.pullAllBy` without support for iteratee
  12. * shorthands.
  13. *
  14. * @private
  15. * @param {Array} array The array to modify.
  16. * @param {Array} values The values to remove.
  17. * @param {Function} [iteratee] The iteratee invoked per element.
  18. * @param {Function} [comparator] The comparator invoked per element.
  19. * @returns {Array} Returns `array`.
  20. */
  21. function basePullAll(array, values, iteratee, comparator) {
  22. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  23. index = -1,
  24. length = values.length,
  25. seen = array;
  26. if (array === values) {
  27. values = copyArray(values);
  28. }
  29. if (iteratee) {
  30. seen = arrayMap(array, baseUnary(iteratee));
  31. }
  32. while (++index < length) {
  33. var fromIndex = 0,
  34. value = values[index],
  35. computed = iteratee ? iteratee(value) : value;
  36. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  37. if (seen !== array) {
  38. splice.call(seen, fromIndex, 1);
  39. }
  40. splice.call(array, fromIndex, 1);
  41. }
  42. }
  43. return array;
  44. }
  45. module.exports = basePullAll;