/** Create an array of unique values that presented in each of the passed arrays */ export function intersection < T > ( ... rest ) ; export function intersection < T > ( a , b , ... rest ) { if ( arguments . length < 2 ) return a ? a . slice ( ) : [ ] ; if ( rest . length ) return intersection ( a , intersection ( b , ... rest ) ) ; return a . filter ( Set . prototype . has , new Set ( b ) ) ; } /** Create an array with unique values from each of the passed arrays */ export function union < T > ( ... rest ) { const set = new Set ( ) ; rest . forEach ( item => item . forEach ( i => set . add ( i ) ) ) ; const result = [ ] ; set . forEach ( value => result . push ( value ) ) ; return result ; } /** Creates an array of unique values from the first array that are not present in the other arrays */ export function complement < T > ( ... rest ) ; export function complement < T > ( a , b , ... rest ) { if ( ! b ) return a ? a . slice ( ) : [ ] ; if ( rest . length > 1 ) return complement ( a , complement ( b , ... rest ) ) ; const setB = new Set ( b ) ; return a . filter ( element => ! setB . has ( element ) ) ; } returns export function fullIntersection < T > ( a , b ) { if ( a . length === 0 && b . length === 0 ) return true ; const [ larger , smaller ] = a . length >= b . length ? [ a , b ] : [ b , a ] ; const set = new Set ( larger ) ; return ! smaller . filter ( ( item ) => ! set . has ( item ) ) . length ; }