esnext.set.intersection.js 947 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var IS_PURE = require('../internals/is-pure');
  3. var $ = require('../internals/export');
  4. var getBuiltIn = require('../internals/get-built-in');
  5. var call = require('../internals/function-call');
  6. var aCallable = require('../internals/a-callable');
  7. var anObject = require('../internals/an-object');
  8. var speciesConstructor = require('../internals/species-constructor');
  9. var iterate = require('../internals/iterate');
  10. // `Set.prototype.intersection` method
  11. // https://github.com/tc39/proposal-set-methods
  12. $({ target: 'Set', proto: true, real: true, forced: IS_PURE }, {
  13. intersection: function intersection(iterable) {
  14. var set = anObject(this);
  15. var newSet = new (speciesConstructor(set, getBuiltIn('Set')))();
  16. var hasCheck = aCallable(set.has);
  17. var adder = aCallable(newSet.add);
  18. iterate(iterable, function (value) {
  19. if (call(hasCheck, set, value)) call(adder, newSet, value);
  20. });
  21. return newSet;
  22. }
  23. });