getMunicipality method

MunicipalityModel getMunicipality (
  1. String municipalityQuery
)

Method that returns the best match of the given municipality with the cuban municipalities. The best match is considered as the cuban municipality of shorter length that contains the given municipality.

Implementation

MunicipalityModel getMunicipality(String municipalityQuery) {
  municipalityQuery = curateMunicipality(municipalityQuery);
  for (var i = 0; i < municipalities.length; ++i) {
    if (municipalities[i].nameCured.contains(municipalityQuery)) {
      return municipalities[i];
    }
  }
  for (var i = municipalities.length - 1; i >= 0; --i) {
    if (municipalityQuery.contains(municipalities[i].nameCured)) {
      return municipalities[i];
    }
  }
  return null;
}