Cleanup lodash.js and ensure _.where returns an empty array when passed an empty properties object.

Former-commit-id: 34d1f8d967806d3c59895eff3a7d4d32262a46ea
This commit is contained in:
John-David Dalton
2012-10-14 18:52:59 -07:00
parent 01ec585a44
commit 16748c0920
4 changed files with 20 additions and 15 deletions

View File

@@ -420,7 +420,7 @@
/**
* Reusable iterator options shared by `every`, `filter`, forEach`, `forIn`,
* `forOwn`, `map`, `reject`, and `some`.
* `forOwn`, `map`, and `some`.
*/
var forEachIteratorOptions = {
'args': 'collection, callback, thisArg',
@@ -1348,7 +1348,6 @@
return false;
}
}
// assume cyclic structures are equal
// the algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3)
@@ -1386,7 +1385,6 @@
}
return result;
}
// deep compare objects
for (var prop in a) {
if (hasOwnProperty.call(a, prop)) {
@@ -1673,7 +1671,8 @@
// avoid merging previously merged cyclic sources
var stackLength = stackA.length;
while (stackLength--) {
if ((found = stackA[stackLength] == source)) {
found = stackA[stackLength] == source;
if (found) {
break;
}
}
@@ -2475,7 +2474,7 @@
* @memberOf _
* @category Collections
* @param {Array|Object|String} collection The collection to iterate over.
* @param {Object} properties The object of properties/values to filter by.
* @param {Object} properties The object of property values to filter by.
* @returns {Array} Returns a new array of elements that contain the given `properties`.
* @example
*
@@ -2492,13 +2491,15 @@
var props = [];
forIn(properties, function(value, prop) { props.push(prop); });
var propsLength = props.length,
var length = props.length,
result = [];
forEach(collection, function(value) {
for (var pass = true, propIndex = 0; propIndex < propsLength; propIndex++) {
var prop = props[propIndex];
if (!(pass = value[prop] === properties[prop])) {
var index = -1, passed = true;
while (++index < length) {
var prop = props[index],
pass = value[prop] === properties[prop];
if (!pass) {
break;
}
}

8
lodash.min.js vendored
View File

@@ -34,7 +34,7 @@ r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return a(t,e,ct.cal
e,t){return t(e),e},s.template=function(e,t,n){e||(e=""),n||(n={});var r,i,o=0,u=s.templateSettings,a="__p += '",f=n.variable||u.variable,l=f;e.replace(RegExp((n.escape||u.escape||et).source+"|"+(n.interpolate||u.interpolate||et).source+"|"+(n.evaluate||u.evaluate||et).source+"|$","g"),function(t,n,i,s,u){a+=e.slice(o,u).replace(nt,c),a+=n?"'+__e("+n+")+'":s?"';"+s+";__p+='":i?"'+((__t=("+i+"))==null?'':__t)+'":"",r||(r=s||V.test(n||i)),o=u+t.length}),a+="';",l||(f="obj",r?a="with("+f+"){"+a+"}":
(n=RegExp("(\\(\\s*)"+f+"\\."+f+"\\b","g"),a=a.replace(Y,"$&"+f+".").replace(n,"$1__d"))),a=(r?a.replace(J,""):a).replace(K,"$1").replace(Q,"$1;"),a="function("+f+"){"+(l?"":f+"||("+f+"={});")+"var __t,__p='',__e=_.escape"+(r?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(l?"":",__d="+f+"."+f+"||"+f)+";")+a+"return __p}";try{i=Function("_","return "+a)(s)}catch(h){throw h.source=a,h}return t?i(t):(i.source=a,i)},s.throttle=function(e,t){function n(){a=new Date,u=r,s=e.
apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(Lt(u),a=r,s=e.apply(o,i)):u||(u=At(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++r<e;)i[r]=t.call(n,r);return i},s.toArray=function(e){if(!e)return[];var t=e.length;return t===+t?(Ht?ht.call(e)==kt:"string"==typeof e)?e.split(""):ct.call(e):T(e)},s.unescape=function(e){return e==r?"":(e+"").replace($,d)},s.union=function(){for(var e=-1,t=st.apply(R,arguments),n=t.length,r=[]
;++e<n;){var i=t[e];0>D(r,i)&&r.push(i)}return r},s.uniq=B,s.uniqueId=function(e){var t=z++;return e?e+t:t},s.values=T,s.where=function(e,t){var r=[];Kt(t,function(e,t){r.push(t)});var i=r.length,s=[];return un(e,function(e){for(var o=n,u=0;u<i&&(o=r[u],o=e[o]===t[o]);u++);o&&s.push(e)}),s},s.without=function(e){for(var t=-1,n=e?e.length:0,r=o(arguments,1,20),i=[];++t<n;){var s=e[t];r(s)||i.push(s)}return i},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&ft.apply(n,arguments
),t.apply(this,n)}},s.zip=function(e){for(var t=-1,n=e?k(L(arguments,"length")):0,r=Array(n);++t<n;)r[t]=L(arguments,t);return r},s.all=sn,s.any=fn,s.collect=an,s.detect=C,s.drop=P,s.each=un,s.foldl=A,s.foldr=O,s.head=M,s.include=N,s.inject=A,s.methods=w,s.select=on,s.tail=P,s.take=M,s.unique=B,I(s),s.prototype.chain=function(){return this.__chain__=n,this},s.prototype.value=function(){return this.__wrapped__},un("pop push reverse shift sort splice unshift".split(" "),function(e){var t=R[e];s.prototype
[e]=function(){var e=this.__wrapped__;return t.apply(e,arguments),Mt&&e.length===0&&delete e[0],this.__chain__&&(e=new s(e),e.__chain__=n),e}}),un(["concat","join","slice"],function(e){var t=R[e];s.prototype[e]=function(){var e=t.apply(this.__wrapped__,arguments);return this.__chain__&&(e=new s(e),e.__chain__=n),e}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(e._=s,define(function(){return s})):q?"object"==typeof module&&module&&module.exports==q?(module.exports=s)._=s:q.
_=s:e._=s})(this);
;++e<n;){var i=t[e];0>D(r,i)&&r.push(i)}return r},s.uniq=B,s.uniqueId=function(e){var t=z++;return e?e+t:t},s.values=T,s.where=function(e,t){var n=[];Kt(t,function(e,t){n.push(t)});var r=n.length,i=[];return un(e,function(e){for(var s=-1;++s<r;){var o=n[s],o=e[o]===t[o];if(!o)break}o&&i.push(e)}),i},s.without=function(e){for(var t=-1,n=e?e.length:0,r=o(arguments,1,20),i=[];++t<n;){var s=e[t];r(s)||i.push(s)}return i},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&ft.apply
(n,arguments),t.apply(this,n)}},s.zip=function(e){for(var t=-1,n=e?k(L(arguments,"length")):0,r=Array(n);++t<n;)r[t]=L(arguments,t);return r},s.all=sn,s.any=fn,s.collect=an,s.detect=C,s.drop=P,s.each=un,s.foldl=A,s.foldr=O,s.head=M,s.include=N,s.inject=A,s.methods=w,s.select=on,s.tail=P,s.take=M,s.unique=B,I(s),s.prototype.chain=function(){return this.__chain__=n,this},s.prototype.value=function(){return this.__wrapped__},un("pop push reverse shift sort splice unshift".split(" "),function(e){var t=
R[e];s.prototype[e]=function(){var e=this.__wrapped__;return t.apply(e,arguments),Mt&&e.length===0&&delete e[0],this.__chain__&&(e=new s(e),e.__chain__=n),e}}),un(["concat","join","slice"],function(e){var t=R[e];s.prototype[e]=function(){var e=t.apply(this.__wrapped__,arguments);return this.__chain__&&(e=new s(e),e.__chain__=n),e}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(e._=s,define(function(){return s})):q?"object"==typeof module&&module&&module.exports==q?(module.exports=
s)._=s:q._=s:e._=s})(this);

View File

@@ -27,6 +27,6 @@ function(e){return ut.call(e)==yt&&e!=+e},p.isNull=function(e){return e===r},p.i
s,p.sortBy=function(e,t,n){var r=[],t=m(t,n);u(e,function(e,n,i){r.push({a:t(e,n,i),b:n,c:e})}),e=r.length;for(r.sort(d);e--;)r[e]=r[e].c;return r},p.sortedIndex=F,p.tap=function(e,t){return t(e),e},p.template=function(e,t,n){e||(e=""),n||(n={});var r,i,s=0,o=p.templateSettings,u="__p += '",a=n.variable||o.variable,f=a;e.replace(RegExp((n.escape||o.escape||Y).source+"|"+(n.interpolate||o.interpolate||Y).source+"|"+(n.evaluate||o.evaluate||Y).source+"|$","g"),function(t,n,i,o,a){u+=e.slice(s,a).replace
(et,g),u+=n?"'+__e("+n+")+'":o?"';"+o+";__p+='":i?"'+((__t=("+i+"))==null?'':__t)+'":"",r||(r=o||J.test(n||i)),s=a+t.length}),u+="';",f||(a="obj",r?u="with("+a+"){"+u+"}":(n=RegExp("(\\(\\s*)"+a+"\\."+a+"\\b","g"),u=u.replace(Q,"$&"+a+".").replace(n,"$1__d"))),u="function("+a+"){"+(f?"":a+"||("+a+"={});")+"var __t,__p='',__e=_.escape"+(r?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(f?"":",__d="+a+"."+a+"||"+a)+";")+u+"return __p}";try{i=Function("_","return "+u)(p)}catch(
l){throw l.source=u,l}return t?i(t):(i.source=u,i)},p.throttle=function(e,t){function n(){a=new Date,u=r,s=e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(St(u),a=r,s=e.apply(o,i)):u||(u=xt(n,f)),s}},p.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++r<e;)i[r]=t.call(n,r);return i},p.toArray=function(e){if(!e)return[];var t=e.length;return t===+t?"string"==typeof e?e.split(""):ot.call(e):k(e)},p.unescape=function(e){return e==r?"":(e+""
).replace(K,w)},p.union=function(){for(var e=-1,t=nt.apply(W,arguments),n=t.length,r=[];++e<n;){var i=t[e];0>B(r,i)&&r.push(i)}return r},p.uniq=I,p.uniqueId=function(e){var t=V++;return e?e+t:t},p.values=k,p.where=function(e,t){var r=[];h(t,function(e,t){r.push(t)});var i=r.length,s=[];return u(e,function(e){for(var o=n,u=0;u<i&&(o=r[u],o=e[o]===t[o]);u++);o&&s.push(e)}),s},p.without=function(e){for(var t=-1,n=e.length,r=[];++t<n;){var i=e[t];0>B(arguments,i,1)&&r.push(i)}return r},p.wrap=function(
e,t){return function(){var n=[e];return arguments.length&&st.apply(n,arguments),t.apply(this,n)}},p.zip=function(e){for(var t=-1,n=e?O(M(arguments,"length")):0,r=Array(n);++t<n;)r[t]=M(arguments,t);return r},p.all=f,p.any=s,p.collect=o,p.detect=A,p.drop=j,p.each=u,p.foldl=_,p.foldr=D,p.head=P,p.include=L,p.inject=_,p.methods=x,p.select=a,p.tail=j,p.take=P,p.unique=I,U(p),p.prototype.chain=function(){return this.__chain__=n,this},p.prototype.value=function(){return this.__wrapped__},u("pop push reverse shift sort splice unshift"
).replace(K,w)},p.union=function(){for(var e=-1,t=nt.apply(W,arguments),n=t.length,r=[];++e<n;){var i=t[e];0>B(r,i)&&r.push(i)}return r},p.uniq=I,p.uniqueId=function(e){var t=V++;return e?e+t:t},p.values=k,p.where=function(e,t){var n=[];h(t,function(e,t){n.push(t)});var r=n.length,i=[];return u(e,function(e){for(var s=-1;++s<r;){var o=n[s],o=e[o]===t[o];if(!o)break}o&&i.push(e)}),i},p.without=function(e){for(var t=-1,n=e.length,r=[];++t<n;){var i=e[t];0>B(arguments,i,1)&&r.push(i)}return r},p.wrap=
function(e,t){return function(){var n=[e];return arguments.length&&st.apply(n,arguments),t.apply(this,n)}},p.zip=function(e){for(var t=-1,n=e?O(M(arguments,"length")):0,r=Array(n);++t<n;)r[t]=M(arguments,t);return r},p.all=f,p.any=s,p.collect=o,p.detect=A,p.drop=j,p.each=u,p.foldl=_,p.foldr=D,p.head=P,p.include=L,p.inject=_,p.methods=x,p.select=a,p.tail=j,p.take=P,p.unique=I,U(p),p.prototype.chain=function(){return this.__chain__=n,this},p.prototype.value=function(){return this.__wrapped__},u("pop push reverse shift sort splice unshift"
.split(" "),function(e){var t=W[e];p.prototype[e]=function(){var e=this.__wrapped__;return t.apply(e,arguments),Tt&&e.length===0&&delete e[0],this.__chain__&&(e=new p(e),e.__chain__=n),e}}),u(["concat","join","slice"],function(e){var t=W[e];p.prototype[e]=function(){var e=t.apply(this.__wrapped__,arguments);return this.__chain__&&(e=new p(e),e.__chain__=n),e}}),z?"object"==typeof module&&module&&module.exports==z?(module.exports=p)._=p:z._=p:e._=p})(this);

View File

@@ -1729,6 +1729,10 @@
deepEqual(_.where(collection, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1, 'b': 2 }]);
});
test('should return an empty array when passed an empty `properties` object', function() {
deepEqual(_.where(array, {}), []);
});
}());
/*--------------------------------------------------------------------------*/