-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (23 loc) · 917 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const rawCities = require('cities.json');
const rawCountries = require('./countries');
// console.log(JSON.stringify(cities,' ', 2));
const countries = {};
const countriesNameIndex = {};
const countriesAlpha3CodeIndex = {};
const countriesAlpha2CodeIndex = {};
const countriesCiocIndex = {};
const countryKeyCode = 'alpha3Code';
rawCountries.map(function (country) {
const countryCode = country[countryKeyCode];
country.cities = [];
countries[countryCode] = country;
countriesNameIndex[country.name] = countryCode;
countriesAlpha2CodeIndex[country.alpha2Code] = countryCode;
countriesAlpha3CodeIndex[country.alpha3Code] = countryCode;
countriesCiocIndex[country.cioc] = countryCode;
});
rawCities.map(function (city) {
city.country = countriesAlpha2CodeIndex[city.country];
countries[city.country].cities.push(city);
});
console.log(JSON.stringify(countries, null, ' '));