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-intersection.js 890B

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