File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments