gradeFor static method

String gradeFor(
  1. GradeSystem system,
  2. int numeric
)

The grade of system nearest to numeric. A value half way between two grades gives the easier one; a value outside the ladder gives its nearest end.

Implementation

static String gradeFor(GradeSystem system, int numeric) {
  final Map<String, int> table = _tables[system]!;
  String nearest = table.keys.first;
  int smallest = (table[nearest]! - numeric).abs();
  for (final MapEntry<String, int> entry in table.entries) {
    final int distance = (entry.value - numeric).abs();
    if (distance < smallest) {
      smallest = distance;
      nearest = entry.key;
    }
  }
  return nearest;
}