@jiminp/tooltool
    Preparing search index...

    Function partitionToMultimap

    • Groups an array into a Map-based multimap using a key extractor.

      Each element is assigned to a group based on the key returned by the extractor function.

      Type Parameters

      • T

        Element type.

      • U

        Key type.

      Parameters

      • arr: T[]

        The array to group.

      • key: (t: T) => U

        Extracts a key from each element.

      Returns Map<U, T[]>

      A Map grouping elements by key.

      This function groups elements into N buckets (not just 2), making it a grouping operation rather than a traditional binary partition.

      const nums = [1, 2, 3, 4, 5];
      const parity = partitionToMultimap(nums, (n) => n % 2 === 0 ? "even" : "odd");
      parity.get("odd"); // [1, 3, 5]
      parity.get("even"); // [2, 4]