Skip to content

Instantly share code, notes, and snippets.

@johndonnelly
Forked from PrateekKumarSingh/Sets.ps1
Created May 6, 2019 20:07
Show Gist options
  • Save johndonnelly/0cbd22c8fce88027b5c97b3a0f467fea to your computer and use it in GitHub Desktop.
Save johndonnelly/0cbd22c8fce88027b5c97b3a0f467fea to your computer and use it in GitHub Desktop.
# define a set
$x = [System.Collections.Generic.HashSet[string]]::new()
'python'.ToCharArray().foreach({[void]$x.add($_)})
$y = [System.Collections.Generic.HashSet[string]]::new()
'powershell'.ToCharArray().foreach({[void$y.add($_)})
$x.ExceptWith($y) # All the elements in x but not in y
# union
$x.UnionWith($y) # Unique elements in x or y or both
# intersection
$x.IntersectWith($y) # Elements in both x and y
$x.SymmetricExceptWith($y) # Elements in x or y but not in both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment