File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
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 ) {
4
9
if ( sets . length === 0 ) return new Set ( ) ;
5
10
if ( sets . length === 1 ) return new Set ( sets [ 0 ] ) ;
6
11
let minSize = Infinity ;
@@ -23,12 +28,21 @@ exports.intersect = sets => {
23
28
}
24
29
}
25
30
return current ;
26
- } ;
31
+ }
27
32
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 ) {
29
40
if ( bigSet . size < smallSet . size ) return false ;
30
41
for ( const item of smallSet ) {
31
42
if ( ! bigSet . has ( item ) ) return false ;
32
43
}
33
44
return true ;
34
- } ;
45
+ }
46
+
47
+ exports . intersect = intersect ;
48
+ exports . isSubset = isSubset ;
You can’t perform that action at this time.
0 commit comments