Composes a new record with all keys and values inverted.
The new record is generated from the result of running each element of the input record through the given transformer function.
The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value.
The type of the input record.
The type of the iterator function.
The record to invert.
The function to transform keys.
A new record with all keys and values inverted.
import { invertBy } from "@std/collections/invert-by";import { assertEquals } from "@std/assert";const record = { a: "x", b: "y", c: "z" };assertEquals( invertBy(record, (key) => String(key).toUpperCase()), { X: ["a"], Y: ["b"], Z: ["c"] }); Copy
import { invertBy } from "@std/collections/invert-by";import { assertEquals } from "@std/assert";const record = { a: "x", b: "y", c: "z" };assertEquals( invertBy(record, (key) => String(key).toUpperCase()), { X: ["a"], Y: ["b"], Z: ["c"] });
Composes a new record with all keys and values inverted.
The new record is generated from the result of running each element of the input record through the given transformer function.
The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value.