import { Country } from '../../data/countries';

export const groupCountriesByPrefix = (countries: readonly Country[]) => {
  const countriesByPrefix = new Map<string, Country[]>();
  countries.forEach((country) => {
    countriesByPrefix.set(country.phone, [
      ...(countriesByPrefix.get(country.phone) ?? []),
      country,
    ]);
  });
  return countriesByPrefix;
};
