Skip to content

unzip

Splits an array of grouped tuples back into separate arrays. The inverse of zip.

import { unzip } from "1o1-utils";
import { unzip } from "1o1-utils/unzip";
function unzip<T>({ array, strategy }: UnzipParams<T>): T[][]
NameTypeRequiredDescription
arrayT[][]YesThe array of tuples to ungroup
strategy"fill" | "truncate"NoHow to handle uneven inner lengths. "fill" (default) pads shorter tuples with undefined; "truncate" cuts to shortest.

T[][] — An array of arrays grouped by tuple position.

unzip({ array: [["a", 1], ["b", 2], ["c", 3]] });
// => [["a", "b", "c"], [1, 2, 3]]
unzip({ array: [["a", 1], ["b"]] });
// => [["a", "b"], [1, undefined]]
unzip({
array: [
["a", 1, true],
["b", 2],
],
strategy: "truncate",
});
// => [["a", "b"], [1, 2]]
  • Throws if array is not an array.
  • Throws if any element of array is not an array.
  • Throws if strategy is not "fill" or "truncate".
  • Returns [] when array is empty.

unzip, transpose, ungroup, split tuples

I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use unzip to split an array of [key, value] tuples into two arrays