Groups an array into a Map-based multimap using a key extractor.
Map
Each element is assigned to a group based on the key returned by the extractor function.
Element type.
Key type.
The array to group.
Extracts a key from each element.
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] Copy
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]
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.