Created
June 28, 2024 13:48
-
-
Save drandarov-io/5198a4d05d9e3e209f1880b7d6fec855 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
param ( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[object[]] $Arrays, | |
[switch] $Split, | |
[ValidateSet("Longest", "Shortest")] | |
[string] $OutputMode = "Shortest" | |
) | |
begin { | |
$zipped = [System.Linq.Enumerable]::Zip($Arrays[0], $Arrays[1], [Func[Object, Object, Object[]]]{ @($args[0], $args[1]) }) | |
# $longest = $Arrays | Sort-Object Length -Descending | Select-Object -First 1 | |
# $null * ($Arrays.Length - 1) + $longest | ForEach-Object { | |
for ($i = 2; $i -lt $Arrays.Length; $i++) { | |
$zipped = [System.Linq.Enumerable]::Zip($zipped, $Arrays[$i], [Func[Object, Object, Object[]]]{ $args[0] + @($args[1]) }) | |
} | |
} | |
process { | |
$zipped | ForEach-Object { | |
$obj = @{} | |
for ($j = 0; $j -lt $_.Length; $j++) { | |
$obj["Value_$j"] = $_[$j] | |
} | |
$Split ? [pscustomobject]$obj : , $_ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment