UNPKG

1.34 kBJavaScriptView Raw
1import arrayMap from './_arrayMap';
2import baseIndexOf from './_baseIndexOf';
3import baseIndexOfWith from './_baseIndexOfWith';
4import baseUnary from './_baseUnary';
5
6/** Used for built-in method references. */
7var arrayProto = Array.prototype;
8
9/** Built-in value references. */
10var splice = arrayProto.splice;
11
12/**
13 * The base implementation of `_.pullAllBy` without support for iteratee
14 * shorthands.
15 *
16 * @private
17 * @param {Array} array The array to modify.
18 * @param {Array} values The values to remove.
19 * @param {Function} [iteratee] The iteratee invoked per element.
20 * @param {Function} [comparator] The comparator invoked per element.
21 * @returns {Array} Returns `array`.
22 */
23function basePullAll(array, values, iteratee, comparator) {
24 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
25 index = -1,
26 length = values.length,
27 seen = array;
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
37 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
38 if (seen !== array) {
39 splice.call(seen, fromIndex, 1);
40 }
41 splice.call(array, fromIndex, 1);
42 }
43 }
44 return array;
45}
46
47export default basePullAll;