esnext.set.symmetric-difference.js 929 B

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