mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +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) {
|
function contains(collection, target, fromIndex) {
|
||||||
var length = collection ? collection.length : 0;
|
var length = collection ? collection.length : 0;
|
||||||
fromIndex = (typeof fromIndex == 'number' && fromIndex) || 0;
|
if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) {
|
||||||
|
var props = keys(collection);
|
||||||
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
length = props.length;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
var index = -1,
|
if (typeof fromIndex == 'number') {
|
||||||
result = false;
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||||
|
} else {
|
||||||
baseEach(collection, function(value) {
|
fromIndex = 0;
|
||||||
if (++index >= fromIndex) {
|
}
|
||||||
return !(result = value === target);
|
if (props) {
|
||||||
|
while (fromIndex < length) {
|
||||||
|
var value = collection[props[fromIndex++]];
|
||||||
|
if (value === target) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
return result;
|
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