mostOccurrences method
Finds the most common value in the list.
Returns a record (tuple) containing the most common value and its frequency. If the list is empty, returns null.
Implementation
(bool, int)? mostOccurrences() {
if (isEmpty) {
return null;
}
final int trueCount = countTrue;
final int falseCount = length - trueCount;
// When counts are equal, true is returned (consistent behavior)
if (trueCount >= falseCount) {
return (true, trueCount);
}
return (false, falseCount);
}