mostFrequent property
Returns the most frequent element in the list.
Implementation
T? get mostFrequent {
if (isEmpty) {
return null;
}
// Find the element with the highest frequency
T? mostFrequentElement;
int maxFrequency = 0;
for (final entry in frequencies.entries) {
if (entry.value > maxFrequency) {
maxFrequency = entry.value;
mostFrequentElement = entry.key;
}
}
return mostFrequentElement;
}