Ensure baseAt uses undefined for non-index values for array-like collections.

This commit is contained in:
John-David Dalton
2014-11-06 20:43:34 -08:00
parent 56ce89e04f
commit f182675a6e

View File

@@ -473,26 +473,6 @@
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
* sorts them in ascending order without guaranteeing a stable sort.
@@ -1423,6 +1403,34 @@
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
* method name arguments.