frequencies property
Returns a map that represents the frequency of each element in the list.
The keys of the map are the elements in the list, and the values are the number of times each element appears in the list.
Example:
final list = [1, 2, 2, 3, 3, 3];
final frequencies = list.frequencies;
print(frequencies); // {1: 1, 2: 2, 3: 3}
Implementation
Map<T, int> get frequencies {
final frequencyMap = <T, int>{};
for (final element in this) {
frequencyMap[element] = (frequencyMap[element] ?? 0) + 1;
}
return frequencyMap;
}