worstMeasureOf function

int? worstMeasureOf(
  1. Map<int, int> errors
)

O compasso com mais erros (a ocorrĂȘncia, base 0), como worstMeasures do resumo: quem tem mais erros, e entre os empatados, o primeiro. null sem erro nenhum.

Implementation

int? worstMeasureOf(Map<int, int> errors) {
  int? worst;
  for (final entry in errors.entries) {
    if (entry.value <= 0) continue;
    if (worst == null) {
      worst = entry.key;
      continue;
    }
    final most = errors[worst]!;
    if (entry.value > most || (entry.value == most && entry.key < worst)) {
      worst = entry.key;
    }
  }
  return worst;
}