Their performance characteristics are probably the same, assuming you want to know wether to use find or some in a specific case. They are both lazy in the same way.
The difference is in the output. find will return the value, some will return a boolean.
I checked the source (1.4.4). some and find both use some (=== any) internally. So even if a native implementation of some is used it benefits both find and some.
Their performance characteristics are probably the same, assuming you want to know wether to use find or some in a specific case. They are both lazy in the same way.
The difference is in the output. find will return the value, some will return a boolean.
I checked the source (1.4.4). some and find both use some (=== any) internally. So even if a native implementation of some is used it benefits both find and some.
If you look into it's source, you will find that those two are identical, _.find actually calls _.some.
_.find = _.detect = function(obj, iterator, context) {
var result;
any(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) {
result = value;
return true;
}
});
return result;
};
var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity);
var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (result || (result = iterator.call(context, value, index, list))) return breaker;
});
return !!result;
};
Videos
I understand how each of these methods work, but they all seem to have similar functions to one another, and I'm not sure as to what situation might call for what method.