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