_basePullAll.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import arrayMap from './_arrayMap.js';
  2. import baseIndexOf from './_baseIndexOf.js';
  3. import baseIndexOfWith from './_baseIndexOfWith.js';
  4. import baseUnary from './_baseUnary.js';
  5. import copyArray from './_copyArray.js';
  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. export default basePullAll;