import { assert } from "./asserts.js";
function defined(arr) {
  let i = arr.findIndex((x) => x === void 0);
  if (i < 0) {
    return arr;
  }
  const defined2 = arr.slice(0, i);
  for (i++; i < arr.length; i++) {
    const x = arr[i];
    if (x !== void 0) {
      defined2.push(x);
    }
  }
  return defined2;
}
function areEqual(arr1, arr2) {
  return arr1.length === arr2.length && arr1.every((e, i) => e === arr2[i]);
}
function zip(a1, a2) {
  assert(a1.length === a2.length, "zip: arrays must have equal length");
  const result = [];
  for (let i = 0; i < a1.length; i++) {
    result.push([a1[i], a2[i]]);
  }
  return result;
}
function last(arr) {
  if (arr.length === 0) {
    return void 0;
  }
  return arr[arr.length - 1];
}
function groupBy(arr, keyFn) {
  const groups = /* @__PURE__ */ new Map();
  for (const el of arr) {
    const key = keyFn(el);
    let group = groups.get(key);
    if (group === void 0) {
      group = [];
      groups.set(key, group);
    }
    group.push(el);
  }
  return groups;
}
export {
  areEqual,
  defined,
  groupBy,
  last,
  zip
};
//# sourceMappingURL=arrays.js.map
