mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Optimize _.contains for arrays.
Former-commit-id: 050743f77e7047f86d5b14b97d35846c9d2e749c
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -3028,12 +3028,13 @@
|
||||
result = false;
|
||||
|
||||
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0;
|
||||
if (length && typeof length == 'number') {
|
||||
result = (isString(collection)
|
||||
? collection.indexOf(target, fromIndex)
|
||||
: indexOf(collection, target, fromIndex)
|
||||
) > -1;
|
||||
} else {
|
||||
if (isArray(collection)) {
|
||||
result = indexOf(collection, target, fromIndex) > -1;
|
||||
}
|
||||
else if (typeof length == 'number' && isString(collection)) {
|
||||
result = collection.indexOf(target, fromIndex) > -1;
|
||||
}
|
||||
else {
|
||||
baseEach(collection, function(value) {
|
||||
if (++index >= fromIndex) {
|
||||
return !(result = value === target);
|
||||
|
||||
Reference in New Issue
Block a user