find.js 513 B

123456789101112131415161718192021
  1. var some = require('./some');
  2. var makeIterator = require('../function/makeIterator_');
  3. /**
  4. * Returns first item that matches criteria
  5. */
  6. function find(obj, callback, thisObj) {
  7. callback = makeIterator(callback, thisObj);
  8. var result;
  9. some(obj, function(value, key, obj) {
  10. if (callback(value, key, obj)) {
  11. result = value;
  12. return true; //break
  13. }
  14. });
  15. return result;
  16. }
  17. module.exports = find;