mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Add unofficial _.where like support for methods like _.find. [closes #159]
Former-commit-id: c6106035af3f3d676cbd3f0a5c785b2c00ad1e9d
This commit is contained in:
30
lodash.js
30
lodash.js
@@ -633,9 +633,23 @@
|
||||
if (!func) {
|
||||
return identity;
|
||||
}
|
||||
if (typeof func != 'function') {
|
||||
var type = typeof func;
|
||||
if (type != 'function') {
|
||||
if (type != 'object') {
|
||||
return function(object) {
|
||||
return object[func];
|
||||
};
|
||||
}
|
||||
var props = keys(func);
|
||||
return function(object) {
|
||||
return object[func];
|
||||
var length = props.length;
|
||||
while (length--) {
|
||||
var result = object[props[length]] === func[props[length]];
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return !!result;
|
||||
};
|
||||
}
|
||||
if (typeof thisArg != 'undefined') {
|
||||
@@ -2748,17 +2762,7 @@
|
||||
* // => [{ 'name': 'moe', 'age': 40 }]
|
||||
*/
|
||||
function where(collection, properties) {
|
||||
var props = keys(properties);
|
||||
return filter(collection, function(object) {
|
||||
var length = props.length;
|
||||
while (length--) {
|
||||
var result = object[props[length]] === properties[props[length]];
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return !!result;
|
||||
});
|
||||
return filter(collection, properties);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user