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.
huazhiyu/node_modules/core-js/internals/set-intersection.js

32 lines
890 B

'use strict';
var aSet = require('../internals/a-set');
var SetHelpers = require('../internals/set-helpers');
var size = require('../internals/set-size');
var getSetRecord = require('../internals/get-set-record');
var iterateSet = require('../internals/set-iterate');
var iterateSimple = require('../internals/iterate-simple');
var Set = SetHelpers.Set;
var add = SetHelpers.add;
var has = SetHelpers.has;
// `Set.prototype.intersection` method
// https://github.com/tc39/proposal-set-methods
module.exports = function intersection(other) {
var O = aSet(this);
var otherRec = getSetRecord(other);
var result = new Set();
if (size(O) > otherRec.size) {
iterateSimple(otherRec.getIterator(), function (e) {
if (has(O, e)) add(result, e);
});
} else {
iterateSet(O, function (e) {
if (otherRec.includes(e)) add(result, e);
});
}
return result;
};