Simplify _.contains. Thanks @phated.

This commit is contained in:
John-David Dalton
2014-04-12 17:35:04 -07:00
parent 8d8b3c2194
commit f1008b1abf

View File

@@ -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;