Skip to content

Ch13.2: Error in mapping laureates to cities #5

Description

@thorsten-de

The code for mapping laureates to citites in this repo differs from the code in the book:
Book:

const relatedCity = cities.find(city =>    city.city === laureate.birth_city && city.country === laureate.birth_country);

Repo:

const relatedCity = cities.find(city => city.city === laureate.birth_city) && cities.find(city => city.country === laureate.birth_country);

This is confusing, because the repo code produces wrong results. For example, it maps too many laureates to "New York City", "United States", as it happens to be the first US city in the laureates data set:

  • If a city is already known in cities, relatedCity will be the first city found for the given birth_country, which is NY for US. Therefore, any city in the US other than the first seen has a maximum of 1 laureate. Same is true for any other country. This can be easily verfied on the cities map.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions