// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
 * Returns a tuple of two arrays with the first one containing all elements in
 * the given array that match the given predicate and the second one containing
 * all that do not.
 *
 * @template T The type of the elements in the array.
 *
 * @param array The array to partition.
 * @param predicate The predicate function to determine which array an element
 * belongs to.
 *
 * @returns A tuple of two arrays. The first array contains all elements that
 * match the predicate, the second contains all elements that do not.
 *
 * @example Basic usage
 * ```ts
 * import { partition } from "@std/collections/partition";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const numbers = [5, 6, 7, 8, 9];
 * const [even, odd] = partition(numbers, (it) => it % 2 === 0);
 *
 * assertEquals(even, [6, 8]);
 * assertEquals(odd, [5, 7, 9]);
 * ```
 */ export function partition(array, predicate) {
  const matches = [];
  const rest = [];
  for (const element of array){
    if (predicate(element)) {
      matches.push(element);
    } else {
      rest.push(element);
    }
  }
  return [
    matches,
    rest
  ];
}
//# sourceMappingURL=data:application/json;base64,[encoded data, 4276 characters]