find.js
498 Bytes
define(['./some', '../function/makeIterator_'], function(some, makeIterator) {
/**
* Returns first item that matches criteria
*/
function find(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var result;
some(obj, function(value, key, obj) {
if (callback(value, key, obj)) {
result = value;
return true; //break
}
});
return result;
}
return find;
});