mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-14 12:47:49 +00:00
Ensure baseAt uses undefined for non-index values for array-like collections.
This commit is contained in:
48
lodash.js
48
lodash.js
@@ -473,26 +473,6 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `_.at` without support for strings and individual
|
|
||||||
* key arguments.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
|
||||||
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
|
|
||||||
* @returns {Array} Returns the new array of picked elements.
|
|
||||||
*/
|
|
||||||
function baseAt(collection, props) {
|
|
||||||
var index = -1,
|
|
||||||
length = props.length,
|
|
||||||
result = Array(length);
|
|
||||||
|
|
||||||
while(++index < length) {
|
|
||||||
result[index] = collection[props[index]];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `compareAscending` which compares values and
|
* The base implementation of `compareAscending` which compares values and
|
||||||
* sorts them in ascending order without guaranteeing a stable sort.
|
* sorts them in ascending order without guaranteeing a stable sort.
|
||||||
@@ -1423,6 +1403,34 @@
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.at` without support for strings and individual
|
||||||
|
* key arguments.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
|
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
|
||||||
|
* @returns {Array} Returns the new array of picked elements.
|
||||||
|
*/
|
||||||
|
function baseAt(collection, props) {
|
||||||
|
var index = -1,
|
||||||
|
length = collection ? collection.length : 0,
|
||||||
|
isArr = isLength(length),
|
||||||
|
propsLength = props.length,
|
||||||
|
result = Array(propsLength);
|
||||||
|
|
||||||
|
while(++index < propsLength) {
|
||||||
|
var key = props[index];
|
||||||
|
if (isArr) {
|
||||||
|
key = parseFloat(key);
|
||||||
|
result[index] = (key > -1 && key < length && key % 1 == 0) ? collection[key] : undefined;
|
||||||
|
} else {
|
||||||
|
result[index] = collection[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.bindAll` without support for individual
|
* The base implementation of `_.bindAll` without support for individual
|
||||||
* method name arguments.
|
* method name arguments.
|
||||||
|
|||||||
Reference in New Issue
Block a user