Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var isArrayLike = require('./isArrayLike'),
2
isIndex = require('./isIndex');
3
4
/**
5
* The base implementation of `_.at` without support for string collections
6
* and individual key arguments.
7
*
8
* @private
9
* @param {Array|Object} collection The collection to iterate over.
10
* @param {number[]|string[]} props The property names or indexes of elements to pick.
11
* @returns {Array} Returns the new array of picked elements.
12
*/
13
function baseAt(collection, props) {
14
var index = -1,
15
isNil = collection == null,
16
isArr = !isNil && isArrayLike(collection),
17
length = isArr ? collection.length : 0,
18
propsLength = props.length,
19
result = Array(propsLength);
20
21
while(++index < propsLength) {
22
var key = props[index];
23
if (isArr) {
24
result[index] = isIndex(key, length) ? collection[key] : undefined;
25
} else {
26
result[index] = isNil ? undefined : collection[key];
27
}
28
}
29
return result;
30
}
31
32
module.exports = baseAt;
33
34