set.prototype.intersection
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -8,2 +8,8 @@ # Changelog | ||
## [v1.1.2](https://github.com/es-shims/Set.prototype.intersection/compare/v1.1.1...v1.1.2) - 2023-12-18 | ||
### Commits | ||
- [Fix] properly implement algorithm [`2d27685`](https://github.com/es-shims/Set.prototype.intersection/commit/2d276854d284bdbbf3b4917f70a02479b414ba35) | ||
## [v1.1.1](https://github.com/es-shims/Set.prototype.intersection/compare/v1.1.0...v1.1.1) - 2023-12-17 | ||
@@ -10,0 +16,0 @@ |
@@ -16,7 +16,9 @@ 'use strict'; | ||
var IteratorValue = require('es-abstract/2023/IteratorValue'); | ||
// var SetDataHas = require('./aos/SetDataHas'); | ||
var SetDataHas = require('./aos/SetDataHas'); | ||
var ToBoolean = require('es-abstract/2023/ToBoolean'); | ||
// var forEach = require('es-abstract/helpers/forEach'); | ||
var forEach = require('es-abstract/helpers/forEach'); | ||
var callBind = require('call-bind'); | ||
var callBound = require('call-bind/callBound'); | ||
var isSet = require('is-set'); | ||
@@ -29,6 +31,4 @@ | ||
/* | ||
var $push = callBound('Array.prototype.push'); | ||
var $sort = callBound('Array.prototype.sort'); | ||
*/ | ||
var $setHas = callBind($Set.prototype.has); | ||
@@ -45,29 +45,22 @@ module.exports = function intersection(other) { | ||
// var resultSetData = []; // step 4 | ||
var resultSetData = []; // step 4 | ||
var thisSize = $setSize(O); // step 5 | ||
var result = new $Set(); | ||
// if (thisSize <= otherRec['[[Size]]']) { // step 6 | ||
$setForEach(O, function (e) { | ||
var inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[Set]]'], [e])); // step 6.b.iii.1 | ||
if (!inOther && e === 0) { | ||
inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[Set]]'], [-e])); | ||
} | ||
if (inOther) { // step 6.b.iii.2 | ||
// var alreadyInResult = SetDataHas(resultSetData, e); // step 6.b.iii.2.b | ||
// if (alreadyInResult) { // step 6.b.iii.2.c | ||
// $push(resultSetData, e); // step 6.b.iii.c.i | ||
$setAdd(result, e); // step 6.b.iii.c.i | ||
// } | ||
} | ||
}); | ||
// return result; // this is an optimization to avoid iterating `resultSetData` | ||
/* | ||
// eslint-disable-next-line no-else-return | ||
if (thisSize <= otherRec['[[Size]]']) { // step 6 | ||
var index = 0; // step 6.a | ||
$setForEach(O, function (e) { | ||
if (index < thisSize) { // step 6.b | ||
index += 1; // step 6.b.ii | ||
var inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[Set]]'], [e])); // step 6.b.iii.1 | ||
if (inOther) { // step 6.b.iii.2 | ||
var alreadyInResult = SetDataHas(resultSetData, e); // step 6.b.iii.2.b | ||
if (!alreadyInResult) { // step 6.b.iii.2.c | ||
$push(resultSetData, e); // step 6.b.iii.c.i | ||
thisSize += 1; | ||
} | ||
} | ||
} | ||
}); | ||
} else { // step 7 | ||
*/ | ||
if (thisSize > otherRec['[[Size]]']) { | ||
var keysIter = GetIteratorFromMethod(otherRec['[[Set]]'], otherRec['[[Keys]]']); // step 7.a | ||
@@ -78,5 +71,4 @@ var next = true; // step 7.b | ||
if (next) { // step 7.c.ii | ||
// var nextValue = IteratorValue(next); // step 7.c.ii.1 | ||
IteratorValue(next); | ||
/* | ||
var nextValue = IteratorValue(next); // step 7.c.ii.1 | ||
if (nextValue === 0) { // step 7.c.ii.2 | ||
@@ -90,21 +82,15 @@ nextValue = +0; | ||
} | ||
*/ | ||
} | ||
} | ||
/* | ||
$sort(resultSetData, function (a, b) { // step 7.e | ||
}); | ||
*/ | ||
} | ||
// var result = OrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »); // step 8 | ||
var result = new $Set(); | ||
// result.[[SetData]] = resultSetData; // step 9 | ||
/* | ||
forEach(resultSetData, function (e) { | ||
$setAdd(result, e); | ||
}); | ||
*/ | ||
return result; // step 10 | ||
}; |
{ | ||
"name": "set.prototype.intersection", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "An ESnext spec-compliant `Set.prototype.intersection` shim/polyfill/replacement that works as far down as ES3", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -346,6 +346,5 @@ 'use strict'; | ||
size: 1, | ||
has: function (x) { | ||
has: function () { | ||
// impossible to avoid this call since we do not have internal set data access | ||
// throw new EvalError('Set.prototype.intersection should not invoke .has on its argument when this.size > arg.size'); | ||
return debug(x) === '-0'; | ||
throw new EvalError('Set.prototype.intersection should not invoke .has on its argument when this.size > arg.size'); | ||
}, | ||
@@ -352,0 +351,0 @@ keys: function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37334
733