Function filterEntries

  • Returns a new record with all entries of the given record except the ones that do not match the given predicate.

    Type Parameters

    • T

      The type of the values in the input record.

    Parameters

    • record: Readonly<Record<string, T>>

      The record to filter entries from.

    • predicate: ((entry: [string, T]) => boolean)

      The function to test each entry for a condition.

        • (entry): boolean
        • Parameters

          • entry: [string, T]

          Returns boolean

    Returns Record<string, T>

    A new record with all entries that match the given predicate.

    import { filterEntries } from "@std/collections/filter-entries";
    import { assertEquals } from "@std/assert";

    const menu = {
    Salad: 11,
    Soup: 8,
    Pasta: 13,
    };

    const myOptions = filterEntries(
    menu,
    ([item, price]) => item !== "Pasta" && price < 10,
    );

    assertEquals(myOptions, { Soup: 8 });