Skip to content

Commit d5eeda7

Browse files
authored
Merge pull request webpack#7133 from webpack/feature/type-set-helpers
chore(types): add type support for SetHelpers
2 parents 14cee2e + 9c3c862 commit d5eeda7

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/util/SetHelpers.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
"use strict";
22

3-
exports.intersect = sets => {
3+
/**
4+
* intersect creates Set containing the intersection of elements between all sets
5+
* @param {Set[]} sets an array of sets being checked for shared elements
6+
* @returns {Set} returns a new Set containing the intersecting items
7+
*/
8+
function intersect(sets) {
49
if (sets.length === 0) return new Set();
510
if (sets.length === 1) return new Set(sets[0]);
611
let minSize = Infinity;
@@ -23,12 +28,21 @@ exports.intersect = sets => {
2328
}
2429
}
2530
return current;
26-
};
31+
}
2732

28-
exports.isSubset = (bigSet, smallSet) => {
33+
/**
34+
* Checks if a set is the subset of another set
35+
* @param {Set} bigSet a Set which contains the original elements to compare against
36+
* @param {Set} smallSet the set whos elements might be contained inside of bigSet
37+
* @returns {boolean} returns true if smallSet contains all elements inside of the bigSet
38+
*/
39+
function isSubset(bigSet, smallSet) {
2940
if (bigSet.size < smallSet.size) return false;
3041
for (const item of smallSet) {
3142
if (!bigSet.has(item)) return false;
3243
}
3344
return true;
34-
};
45+
}
46+
47+
exports.intersect = intersect;
48+
exports.isSubset = isSubset;

0 commit comments

Comments
 (0)