Frequency
Rather than keeping track of values, maybe you want to keep track of the number of times an event occurs, without caring much about the data itself.
In ixfx, we can use Trackers.frequency . Note that the object is mutable.
Adding and clearing
Clear all data
Calculating
Get the count of a specific group. Returns undefined
if group is not found.
It can be useful to work with the relative frequency rather than the absolute amount. For example, apples
appears 40% of the time:
To find the smallest, largest, average frequencies as well as the total frequency (ie. how many things have been added):
Iterating
You can get the data as an array and iterate:
Custom objects
To keep track of objects, provide a function that creates a string for the items you’re adding. This allows you to group by different fields, or some combination of fields.
In the below example, cars are grouped by their make:
Demo
The below demo calculates frequency distribution of letters in a string.