mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
Simplify _.contains. Thanks @phated.
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -3710,23 +3710,14 @@
|
||||
function contains(collection, target, fromIndex) {
|
||||
var length = collection ? collection.length : 0;
|
||||
if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) {
|
||||
var props = keys(collection);
|
||||
length = props.length;
|
||||
collection = values(collection);
|
||||
length = collection.length;
|
||||
}
|
||||
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 false;
|
||||
}
|
||||
if (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
||||
if (fromIndex >= length) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user