mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57: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) {
|
function contains(collection, target, fromIndex) {
|
||||||
var length = collection ? collection.length : 0;
|
var length = collection ? collection.length : 0;
|
||||||
if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) {
|
if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) {
|
||||||
var props = keys(collection);
|
collection = values(collection);
|
||||||
length = props.length;
|
length = collection.length;
|
||||||
}
|
}
|
||||||
if (typeof fromIndex == 'number') {
|
if (typeof fromIndex == 'number') {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||||
} else {
|
} else {
|
||||||
fromIndex = 0;
|
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 (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
||||||
if (fromIndex >= length) {
|
if (fromIndex >= length) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user