UNPKG

1.23 kBJavaScriptView Raw
1import baseCastPath from './_baseCastPath';
2import isIndex from './_isIndex';
3import isKey from './_isKey';
4import last from './last';
5import parent from './_parent';
6
7/** Used for built-in method references. */
8var arrayProto = Array.prototype;
9
10/** Built-in value references. */
11var splice = arrayProto.splice;
12
13/**
14 * The base implementation of `_.pullAt` without support for individual
15 * indexes or capturing the removed elements.
16 *
17 * @private
18 * @param {Array} array The array to modify.
19 * @param {number[]} indexes The indexes of elements to remove.
20 * @returns {Array} Returns `array`.
21 */
22function basePullAt(array, indexes) {
23 var length = array ? indexes.length : 0,
24 lastIndex = length - 1;
25
26 while (length--) {
27 var index = indexes[length];
28 if (lastIndex == length || index != previous) {
29 var previous = index;
30 if (isIndex(index)) {
31 splice.call(array, index, 1);
32 }
33 else if (!isKey(index, array)) {
34 var path = baseCastPath(index),
35 object = parent(array, path);
36
37 if (object != null) {
38 delete object[last(path)];
39 }
40 }
41 else {
42 delete array[index];
43 }
44 }
45 }
46 return array;
47}
48
49export default basePullAt;