• Returns all the entities are distinct by the property value argument.

    Note that the implementation uses a Map<string, E> to index the entities by key. Therefore the more recent occurences matching a key instance will overwrite the previous ones.

    Type Parameters

    • E

    • K extends string | number | symbol

    Parameters

    • entities: E[]

      The entities in the array.

    • property: K

      The name of the property to check for distinct values by.

    Returns E[]

    Example

     let todos: Todo[] = [
    { id: 1, title: "Lets do it!" },
    { id: 1, title: "Lets do it again!" },
    { id: 2, title: "All done!" }
    ];

    let todos2: Todo[] = [
    { id: 1, title: "Lets do it!" },
    { id: 2, title: "All done!" }
    ];

    expect(distinct(todos, "id").length).toEqual(2);
    expect(distinct(todos2, "id").length).toEqual(2);

Generated using TypeDoc