Created
June 7, 2019 07:35
-
-
Save chriskuech/f260928e780ae835726b237ed762af1a to your computer and use it in GitHub Desktop.
This file contains 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
# modified from https://github.com/chriskuech/functional | |
function recursiveEquality($a, $b) { | |
# recursive step for arrays | |
if ($a -is [array] -and $b -is [array]) { | |
if ($a.Count -ne $b.Count) { | |
return $false | |
} | |
$inequalIndexes = 0..($a.Count - 1) | ? { -not (recursiveEquality $a[$_] $b[$_]) } | |
return $inequalIndexes.Count -eq 0 | |
} | |
# recursive step for hashtables | |
if ($a -is [hashtable] -and $b -is [hashtable]) { | |
$inequalKeys = $a.Keys + $b.Keys ` | |
| Sort-Object -Unique ` | |
| ? { -not (recursiveEquality $a[$_] $b[$_]) } | |
return $inequalKeys.Count -eq 0 | |
} | |
# recursive step for objects | |
# use a helper function to circumvent this PowerShell bug: | |
# https://github.com/PowerShell/PowerShell/issues/9557 | |
if ((isPsCustomObject $a) -and (isPsCustomObject $b)) { | |
$inequalKeys = $a.psobject.Properties + $b.psobject.Properties ` | |
| % Name ` | |
| Sort-Object -Unique ` | |
| ? { -not (recursiveEquality $a.$_ $b.$_) } | |
return $inequalKeys.Count -eq 0 | |
} | |
# base case | |
return $a.GetType() -eq $b.GetType() -and $a -eq $b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment