mostOccurrences method

  1. @useResult
Occurrence<bool>? mostOccurrences()

Finds the most common value in the list.

Returns an Occurrence containing the most common value and its frequency. If the list is empty, returns null.

Implementation

@useResult
Occurrence<bool>? 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 Occurrence<bool>(true, trueCount);
  }

  return Occurrence<bool>(false, falseCount);
}