// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { minOf } from "./min_of.ts";
/**
 * Builds N-tuples of elements from the given N arrays with matching indices,
 * stopping when the smallest array's end is reached.
 *
 * @template T the type of the tuples produced by this function.
 *
 * @param arrays The arrays to zip.
 *
 * @returns A new array containing N-tuples of elements from the given arrays.
 *
 * @example Basic usage
 * ```ts
 * import { zip } from "@std/collections/zip";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const numbers = [1, 2, 3, 4];
 * const letters = ["a", "b", "c", "d"];
 * const pairs = zip(numbers, letters);
 *
 * assertEquals(
 *   pairs,
 *   [
 *     [1, "a"],
 *     [2, "b"],
 *     [3, "c"],
 *     [4, "d"],
 *   ],
 * );
 * ```
 */ export function zip(...arrays) {
  const minLength = minOf(arrays, (element)=>element.length) ?? 0;
  const result = new Array(minLength);
  for(let i = 0; i < minLength; i += 1){
    const arr = arrays.map((it)=>it[i]);
    result[i] = arr;
  }
  return result;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vanNyLmlvL0BzdGQvY29sbGVjdGlvbnMvMC4yMjQuMi96aXAudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gQ29weXJpZ2h0IDIwMTgtMjAyNCB0aGUgRGVubyBhdXRob3JzLiBBbGwgcmlnaHRzIHJlc2VydmVkLiBNSVQgbGljZW5zZS5cbi8vIFRoaXMgbW9kdWxlIGlzIGJyb3dzZXIgY29tcGF0aWJsZS5cblxuaW1wb3J0IHsgbWluT2YgfSBmcm9tIFwiLi9taW5fb2YudHNcIjtcblxuLyoqXG4gKiBCdWlsZHMgTi10dXBsZXMgb2YgZWxlbWVudHMgZnJvbSB0aGUgZ2l2ZW4gTiBhcnJheXMgd2l0aCBtYXRjaGluZyBpbmRpY2VzLFxuICogc3RvcHBpbmcgd2hlbiB0aGUgc21hbGxlc3QgYXJyYXkncyBlbmQgaXMgcmVhY2hlZC5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