Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var baseAt = require('../internal/baseAt'),
2
baseCompareAscending = require('../internal/baseCompareAscending'),
3
baseFlatten = require('../internal/baseFlatten'),
4
basePullAt = require('../internal/basePullAt'),
5
restParam = require('../function/restParam');
6
7
/**
8
* Removes elements from `array` corresponding to the given indexes and returns
9
* an array of the removed elements. Indexes may be specified as an array of
10
* indexes or as individual arguments.
11
*
12
* **Note:** Unlike `_.at`, this method mutates `array`.
13
*
14
* @static
15
* @memberOf _
16
* @category Array
17
* @param {Array} array The array to modify.
18
* @param {...(number|number[])} [indexes] The indexes of elements to remove,
19
* specified as individual indexes or arrays of indexes.
20
* @returns {Array} Returns the new array of removed elements.
21
* @example
22
*
23
* var array = [5, 10, 15, 20];
24
* var evens = _.pullAt(array, 1, 3);
25
*
26
* console.log(array);
27
* // => [5, 15]
28
*
29
* console.log(evens);
30
* // => [10, 20]
31
*/
32
var pullAt = restParam(function(array, indexes) {
33
indexes = baseFlatten(indexes);
34
35
var result = baseAt(array, indexes);
36
basePullAt(array, indexes.sort(baseCompareAscending));
37
return result;
38
});
39
40
module.exports = pullAt;
41
42