Methods
Set

Set Methods

import { set } from 'ajuda'

difference

Description

Takes two Sets as arguments and returns a Set that has elements not contained in both Sets.

Please note that this operation computes the Symmetric Set Difference.

set.difference(set: Set<any>, _set: Set<any>): Set<any>

Parameters

{Set} set A Set of elements.

{Set} _set A Set of elements.

Returns

{Set} A Set containing elements NOT found in both Sets.

Example

let SetA = new Set([1, 2, 3, 4, 5])
let SetB = new Set([2, 3, 4, 5, 6])
 
Array.from(set.difference(SetA, SetB))
// [1, 6]

intersection

Description

Takes two Sets as arguments and returns a Set that has elements contained in both Sets.

set.intersection(set: Set<any>, _set: Set<any>): Set<any>

Parameters

{Set} set A Set of elements.

{Set} _set A Set of elements.

Returns

{Set} A Set containing elements found in both Sets.

Example

let SetA = new Set([1, 2, 3, 4, 5])
let SetB = new Set([2, 3, 4, 5, 6])
 
Array.from(set.intersection(SetA, SetB))
// [2, 3, 4, 5]

union

Description

Takes two Sets as arguments and returns a Set of merged elements from both Sets.

set.union(set: Set<any>, _set: Set<any>): Set<any>

Parameters

{Set} set A Set of elements.

{Set} _set A Set of elements.

Returns

{Set} A Set containing merged elements from both Sets.

Example

let SetA = new Set([1, 2, 3, 4, 5])
let SetB = new Set([2, 3, 4, 5, 6])
 
Array.from(set.union(SetA, SetB))
// [1, 2, 3, 4, 5, 6]