diff --git a/build.js b/build.js index 1d59677ef..8e0d9b5cd 100644 --- a/build.js +++ b/build.js @@ -119,7 +119,7 @@ 'cloneDeep': ['baseClone', 'baseCreateCallback'], 'compact': [], 'compose': ['isFunction'], - 'contains': ['baseEach', 'getIndexOf', 'isString'], + 'contains': ['baseEach', 'getIndexOf', 'isArray', 'isString'], 'countBy': ['createAggregator'], 'createCallback': ['baseCreateCallback', 'baseIsEqual', 'isObject', 'keys'], 'curry': ['createBound'], @@ -2924,7 +2924,7 @@ _.pull(funcDepMap.wrapperValueOf, 'wrapperToString'); } if (!isLodash('contains')) { - _.pull(funcDepMap.contains, 'isString'); + _.pull(funcDepMap.contains, 'isArray', 'isString'); } if (!isLodash('flatten')) { _.pull(funcDepMap.flatten, 'map'); diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index c7c3b702a..1f9589af3 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -3009,12 +3009,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); diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 53eec1c1a..eb1e06951 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -17,9 +17,9 @@ var g=n&&n.__bindData__;if(g)return!a||1&g[1]||(g[4]=u),!a&&1&g[1]&&(t|=8),!l||4 var u=[];if(Le.enumPrototypes&&u.push('!(G&&n=="prototype")'),Le.enumErrorProps&&u.push('!(F&&(n=="message"||n=="name"))'),n.j&&n.f)r+="var C=-1,D=B[typeof t]&&v(t),u=D?D.length:0;while(++Ck;k++)r+="n='"+n.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",n.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+n.g+"}"; r+="}"}return(n.b||Le.nonEnumArgs)&&(r+="}"),r+=n.c+";return E",t=t("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",e+r+"}"),s(n),t(V,q,oe,ve,_,pt,qe,dt,n.f,ae,U,ze,M,ie,we)}function at(n){return yt(n)?Ce(n):{}}function it(n){return He[n]}function lt(){var t=(t=y.indexOf)===Rt?n:t;return t}function ft(n){var t,e;return!n||we.call(n)!=G||(t=n.constructor,vt(t)&&!(t instanceof t))||!Le.argsClass&&pt(n)||!Le.nodeClass&&f(n)?!1:Le.ownLast?(nr(n,function(n,t,r){return e=ve.call(r,t),!1}),false!==e):(nr(n,function(n,t){e=t }),e===v||ve.call(n,e))}function ct(n){return Ue[n]}function pt(n){return n&&typeof n=="object"?we.call(n)==$:!1}function st(n,t,e){var r=We(n),u=r.length;for(t=V(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function gt(n){var t=[];return nr(n,function(n,e){vt(n)&&t.push(e)}),t.sort()}function ht(n){for(var t=-1,e=We(n),r=e.length,u={};++te?Ie(0,o+e):e)||0,o&&typeof o=="number"?a=-1<(dt(n)?n.indexOf(t,e):u(n,t,e)):Xe(n,function(n){return++re?Ie(0,o+e):e)||0,qe(n)?a=-1o&&(o=i)}}else t=!t&&dt(n)?r:y.createCallback(t,e,3),Xe(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function St(n,t,e,r){var u=3>arguments.length;if(t=V(t,r,4),qe(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=V(t,r,4),Ct(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function It(n){var t=-1,e=n?n.length:0,r=Ut(typeof e=="number"?e:0); return xt(n,function(n){var e=Mt(++t);r[t]=r[e],r[e]=n}),r}function Bt(n,t,e){var r;if(t=y.createCallback(t,e,3),qe(n)){e=-1;for(var u=n.length;++e=w&&u===n;if(f){var c=o(i);c?(u=t,i=c):f=!1}for(;++ru(i,c)&&l.push(c);return f&&s(i),l }function Nt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,e,3);++or?Ie(0,u+r):r||0}else if(r)return r=$t(t,e),t[r]===e?r:-1;return n(t,e,r)}function Ft(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=y.createCallback(t,e,3);++u -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 { forOwn(collection, function(value) { if (++index >= fromIndex) { return !(result = value === target); diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 3805db39f..29c700fa8 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -16,7 +16,7 @@ if(f!=q)return!1;var f=n.constructor,p=t.constructor;if(f!=p&&!(ht(f)&&f instanc }for(;++af(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.b),p(h)):u&&c(h),s}function ut(n){return function(t,e,r){var u={};e=Q.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Ie(0,o+e):e)||0,o&&typeof o=="number"?a=-1<(mt(n)?n.indexOf(t,e):u(n,t,e)):y(n,function(n){return++re?Ie(0,o+e):e)||0,ze(n)?a=-1o&&(o=i)}}else t=!t&&mt(n)?r:Q.createCallback(t,e,3),kt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Et(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Ht(r);++earguments.length;t=Z(t,r,4);var o=-1,a=n.length;if(typeof a=="number")for(u&&(e=n[++o]);++o -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); diff --git a/test/test.js b/test/test.js index 76aebebf0..8e6d9502f 100644 --- a/test/test.js +++ b/test/test.js @@ -562,6 +562,7 @@ (function() { _.forEach({ + 'an `arguments` object': arguments, 'an array': [1, 2, 3, 1, 2, 3], 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 1, 'e': 2, 'f': 3 }, 'a string': '123123' @@ -598,7 +599,7 @@ strictEqual(_.contains(collection, 'd'), false); }); }); - }()); + }(1, 2, 3, 1, 2, 3)); /*--------------------------------------------------------------------------*/