esnext.set.find.js 698 B

123456789101112131415161718
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var bind = require('../internals/function-bind-context');
  4. var aSet = require('../internals/a-set');
  5. var iterate = require('../internals/set-iterate');
  6. // `Set.prototype.find` method
  7. // https://github.com/tc39/proposal-collection-methods
  8. $({ target: 'Set', proto: true, real: true, forced: true }, {
  9. find: function find(callbackfn /* , thisArg */) {
  10. var set = aSet(this);
  11. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  12. var result = iterate(set, function (value) {
  13. if (boundFunction(value, value, set)) return { value: value };
  14. }, true);
  15. return result && result.value;
  16. }
  17. });