mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Ensure _.contains works with a fromIndex for objects.
This commit is contained in:
49
lodash.js
49
lodash.js
@@ -3645,31 +3645,34 @@
|
||||
*/
|
||||
function contains(collection, target, fromIndex) {
|
||||
var length = collection ? collection.length : 0;
|
||||
fromIndex = (typeof fromIndex == 'number' && fromIndex) || 0;
|
||||
|
||||
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
||||
if (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
||||
if (fromIndex >= length) {
|
||||
return false;
|
||||
}
|
||||
return nativeContains
|
||||
? nativeContains.call(collection, target, fromIndex)
|
||||
: collection.indexOf(target, fromIndex) > -1;
|
||||
}
|
||||
var indexOf = getIndexOf();
|
||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
||||
return indexOf(collection, target, fromIndex) > -1;
|
||||
if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) {
|
||||
var props = keys(collection);
|
||||
length = props.length;
|
||||
}
|
||||
var index = -1,
|
||||
result = false;
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
if (++index >= fromIndex) {
|
||||
return !(result = value === target);
|
||||
if (typeof fromIndex == 'number') {
|
||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||
} else {
|
||||
fromIndex = 0;
|
||||
}
|
||||
if (props) {
|
||||
while (fromIndex < length) {
|
||||
var value = collection[props[fromIndex++]];
|
||||
if (value === target) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
if (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
||||
if (fromIndex >= length) {
|
||||
return false;
|
||||
}
|
||||
return nativeContains
|
||||
? nativeContains.call(collection, target, fromIndex)
|
||||
: collection.indexOf(target, fromIndex) > -1;
|
||||
}
|
||||
var indexOf = getIndexOf();
|
||||
return indexOf(collection, target, fromIndex) > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user