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