groupCountries function

Map<String, List<Country>> groupCountries(
  1. List<Country> countries
)

Implementation

Map<String, List<Country>> groupCountries(List<Country> countries) {
  Map<String, List<Country>> grouped = {};
  for (var country in countries) {
    String firstLetter = country.country[0];
    if (!grouped.containsKey(firstLetter)) {
      grouped[firstLetter] = [];
    }
    grouped[firstLetter]!.add(country);
  }
  return grouped;
}