filterKeys
import { filterKeys } from "jsr:@ende/collections";function
function filterKeys<T>(record: Readonly<Record<string, T>>, predicate: (key: string) => boolean): Record<string, T>Returns a new record with all entries of the given record except the ones that have a key that does not match the given predicate.
record: Readonly<Record<string, T>>The record to filter keys from.
predicate: (key: string) => booleanThe function to test each key for a condition.
Returns
A new record with all entries that have a key that matches the given predicate.
Example: Basic usage
import { filterKeys } from "@ende/collections/filter-keys";
import { assertEquals } from "@ende/assert";
const menu = {
Salad: 11,
Soup: 8,
Pasta: 13,
};
const menuWithoutSalad = filterKeys(menu, (item) => item !== "Salad");
assertEquals(
menuWithoutSalad,
{
Soup: 8,
Pasta: 13,
},
);