Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Created May 10, 2019 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/8a244c279a9eace3d74285395da4f3e3 to your computer and use it in GitHub Desktop.
Save IISResetMe/8a244c279a9eace3d74285395da4f3e3 to your computer and use it in GitHub Desktop.
function Get-DistinctUnion
{
param(
[array]$Source,
[array]$Other
)
$temp = [System.Collections.Generic.HashSet[object]]::new($Source)
$temp.UnionWith($Other)
return $temp
}
$array1 = 1..3
$array2 = 3..5
Get-DistinctUnion -Source $array1 -Other $array2
# This will also work
$set1 = [System.Collections.Generic.HashSet[int]]::new([int[]]$array1)
$set2 = [System.Collections.Generic.HashSet[int]]::new([int[]]$array2)
Get-DistinctUnion -Source $set1 -Other $set2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment