ixfx
    Preparing search index...

    Class FrequencyTracker<V>

    Frequency keeps track of how many times a particular value is seen, but unlike a Map it does not store the data. By default compares items by value (via JSON.stringify).

    Fires change event when items are added or it is cleared.

    Overview

    const fh = new FrequencyTracker();
    fh.add(value); // adds a value
    fh.clear(); // clears all data
    fh.keys() / .values() // returns an iterator for keys and values
    fh.toArray(); // returns an array of data in the shape [[key,freq],[key,freq]...]

    Usage

    const fh = new FrequencyTracker();
    fh.add(`apples`); // Count an occurence of `apples`
    fh.add(`oranges)`;
    fh.add(`apples`);

    const fhData = fh.toArray(); // Expect result [[`apples`, 2], [`oranges`, 1]]
    fhData.forEach((d) => {
    const [key,freq] = d;
    console.log(`Key '${key}' occurred ${freq} time(s).`);
    })

    Custom key string

    const fh = frequency( person => person.name);
    // All people with name `Samantha` will be counted in same group
    fh.add({name:`Samantha`, city:`Brisbane`});

    Type Parameters

    • V

      Type of items

    Hierarchy (View Summary)

    Index

    Accessors

    Constructors

    Methods

    • Add one or more values, firing change event.

      Parameters

      • ...values: V[]

        Values to add. Fires change event after adding item(s)

      Returns void

    • Parameters

      • value: string | V

        Value to count

      Returns undefined | number

      Frequency of value, or undefined if it does not exist

    • Parameters

      • value: string | V

        Value to count

      Returns undefined | number

      Relative frequency of value, or undefined if it does not exist