Skip to content

Instantly share code, notes, and snippets.

@drandarov-io
Created June 28, 2024 13:48
Show Gist options
  • Save drandarov-io/5198a4d05d9e3e209f1880b7d6fec855 to your computer and use it in GitHub Desktop.
Save drandarov-io/5198a4d05d9e3e209f1880b7d6fec855 to your computer and use it in GitHub Desktop.
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