Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

set-difference.js 891B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var aSet = require('../internals/a-set');
  3. var SetHelpers = require('../internals/set-helpers');
  4. var clone = require('../internals/set-clone');
  5. var size = require('../internals/set-size');
  6. var getSetRecord = require('../internals/get-set-record');
  7. var iterateSet = require('../internals/set-iterate');
  8. var iterateSimple = require('../internals/iterate-simple');
  9. var has = SetHelpers.has;
  10. var remove = SetHelpers.remove;
  11. // `Set.prototype.difference` method
  12. // https://github.com/tc39/proposal-set-methods
  13. module.exports = function difference(other) {
  14. var O = aSet(this);
  15. var otherRec = getSetRecord(other);
  16. var result = clone(O);
  17. if (size(O) <= otherRec.size) iterateSet(O, function (e) {
  18. if (otherRec.includes(e)) remove(result, e);
  19. });
  20. else iterateSimple(otherRec.getIterator(), function (e) {
  21. if (has(O, e)) remove(result, e);
  22. });
  23. return result;
  24. };