Last active
July 16, 2019 10:58
-
-
Save IISResetMe/57ce7b76e1001974a4f7170e10775875 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Compare-Array | |
{ | |
param( | |
[array]$Ref, | |
[array]$Diff | |
) | |
$max = [math]::Max($Ref.Length,$Diff.Length) | |
for($i = 0; $i -lt $max; $i++){ | |
if($Ref[$i] -ne $Diff[$i]){ | |
[pscustomobject]@{ | |
Index = $i | |
Left = $Ref[$i] | |
Right = $Diff[$i] | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Compare-StringSet | |
{ | |
param( | |
[string[]]$Ref, | |
[string[]]$Diff, | |
[switch]$CaseSensitive | |
) | |
$Comparer = if($CaseSensitive){ | |
[System.StringComparer]::InvariantCulture | |
} | |
else { | |
[System.StringComparer]::InvariantCultureIgnoreCase | |
} | |
$Results = [ordered]@{ | |
Left = @() | |
Both = @() | |
Right = @() | |
} | |
$temp = [System.Collections.Generic.HashSet[string]]::new($Ref, $Comparer) | |
$temp.IntersectWith($Diff) | |
$Results['Both'] = $temp | |
$temp = [System.Collections.Generic.HashSet[string]]::new($Ref,[System.StringComparer]::CurrentCultureIgnoreCase) | |
$temp.ExceptWith($Diff) | |
$Results['Left'] = $temp | |
$temp = [System.Collections.Generic.HashSet[string]]::new($Diff,[System.StringComparer]::CurrentCultureIgnoreCase) | |
$temp.ExceptWith($Ref) | |
$Results['Right'] = $temp | |
return [pscustomobject]$Results | |
} |
@fatherjack I added a Compare-StringSet
example as well:
$ref,$dif = @(
,@('a','b','c')
,@('b','c','d')
)
Compare-StringSet $ref $dif
Output:
Left Both Right
---- ---- -----
{a} {b, c} {d}
Fabulous!
Many thanks
J
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting start but doesnt show difference (left or right) on this trial
results :
"expectation" would be