esnext.set.intersection.js 895 B

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