RosettaCodeData/Task/Loop-over-multiple-arrays-simultaneously/Jq/loop-over-multiple-arrays-simultaneously-2.jq
2023-07-01 13:44:08 -04:00

8 lines
237 B
Text

# transpose a possibly jagged matrix
def transpose:
if . == [] then []
else (.[1:] | transpose) as $t
| .[0] as $row
| reduce range(0; [($t|length), (.[0]|length)] | max) as $i
([]; . + [ [ $row[$i] ] + $t[$i] ])
end;