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