Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- regions = [
- // ======================================== REGIONS START
- {
- type: "region",
- id: "3128",
- title: "Africa and Middle East",
- parent: null,
- count: 15945
- },
- {
- type: "region",
- id: "3122",
- title: "AsiaAsiaAsia Pacific",
- parent: null,
- count: 789643
- },
- {
- type: "region",
- id: "3123",
- title: "Australia and Oceania",
- parent: null,
- count: 54589
- },
- {
- type: "region",
- id: "3114",
- title: "Europe and Central Asia",
- parent: null,
- count: 94589
- },
- {
- type: "region",
- id: "3132",
- title: "North and South America",
- parent: null,
- count: 18754
- },
- // ======================================== REGIONS END
- // ======================================== AFRICA_AND_MIDDLE_EAST COUNTRIES START
- {
- type: "country",
- id: "algeria",
- title: "Algeria",
- parent: "3128",
- iso_code: "DZ",
- count: 1834
- },
- {
- type: "country",
- id: "libya",
- title: "Libya",
- parent: "3128",
- iso_code: "LY",
- count: 1673
- },
- {
- type: "country",
- id: "egypt",
- title: "Egypt",
- parent: "3128",
- iso_code: "EG",
- count: 1931
- },
- {
- type: "country",
- id: "morocco",
- title: "Morocco",
- parent: "3128",
- iso_code: "MA",
- count: 2145
- },
- // ======================================== AFRICA_AND_MIDDLE_EAST COUNTRIES END
- // ======================================== ASIA_PACIFIC COUNTRIES START
- {
- type: "country",
- id: "ind",
- title: "India",
- parent: "3122",
- iso_code: "IN",
- count: 1956
- },
- {
- type: "country",
- id: "pakistan",
- title: "Pakistan",
- parent: "3122",
- iso_code: "PK",
- count: 2374
- },
- {
- type: "country",
- id: "chn",
- title: "China",
- parent: "3122",
- iso_code: "CN",
- count: 254789
- },
- {
- type: "country",
- id: "nepal",
- title: "Nepal",
- parent: "3122",
- iso_code: "NP",
- count: 1587
- },
- // ======================================== ASIA_PACIFIC COUNTRIES START END
- // ======================================== AUSTRALIA_AND_OCEANIA COUNTRIES START
- {
- type: "country",
- id: "australia",
- title: "Australia",
- parent: "3123",
- iso_code: "AU",
- count: 41587
- },
- {
- type: "country",
- id: "new_zeland",
- title: "New Zeland",
- parent: "3123",
- iso_code: "NZ",
- count: 11183
- },
- {
- type: "country",
- id: "papua_new_guinea",
- title: "Papua New Guinea",
- parent: "3123",
- iso_code: "PG",
- count: 24981
- },
- {
- type: "country",
- id: "solomon_islands",
- title: "Solomon Islands",
- parent: "3123",
- iso_code: "SB",
- count: 10935
- },
- // ======================================== AUSTRALIA_AND_OCEANIA COUNTRIES END
- // ======================================== EUROPE_AND_CENTRAL_ASIA COUNTRIES START
- {
- type: "country",
- id: "ru",
- title: "Russia",
- parent: "3114",
- iso_code: "RU",
- count: 148502
- },
- {
- type: "country",
- id: "belarus",
- title: "Belarus",
- parent: "3114",
- iso_code: "BY",
- count: 24154
- },
- {
- type: "country",
- id: "poland",
- title: "Poland",
- parent: "3114",
- iso_code: "PL",
- count: 24154
- },
- {
- type: "country",
- id: "kazakhstan",
- title: "Kazakhstan",
- parent: "3114",
- iso_code: "KZ",
- count: 48917
- },
- // ======================================== EUROPE_AND_CENTRAL_ASIA COUNTRIES END
- // ======================================== NORTH_AND_SOUTH_AMERICA COUNTRIES START
- {
- type: "country",
- id: "canada",
- title: "Canada",
- parent: "3132",
- iso_code: "CA",
- count: 87917
- },
- {
- type: "country",
- id: "united_states",
- title: "United States of America",
- parent: "3132",
- iso_code: "US",
- count: 24887
- },
- {
- type: "country",
- id: "brazil",
- title: "Brazil",
- parent: "3132",
- iso_code: "BR",
- count: 46357
- },
- {
- type: "country",
- id: "argentina",
- title: "Argentina",
- parent: "3132",
- iso_code: "AR",
- count: 21036
- },
- // ======================================== NORTH_AND_SOUTH_AMERICA COUNTRIES END
- // ======================================== CHINA PROVINCES START
- {
- type: "province",
- id: "xinjiang",
- title: "Xinjiang",
- parent: "chn",
- iso_code: "cn-xj",
- count: 234
- },
- {
- type: "province",
- id: "qinghai",
- title: "Qinghai",
- parent: "chn",
- iso_code: "cn-qh",
- count: 942
- },
- {
- type: "province",
- id: "yunnan",
- title: "Yunnan",
- parent: "chn",
- iso_code: "cn-yn",
- count: 821
- },
- {
- type: "province",
- id: "hunan",
- title: "Hunan",
- parent: "chn",
- iso_code: "cn-hn",
- count: 744
- },
- {
- type: "province",
- id: "fujian",
- title: "Fujian",
- parent: "chn",
- iso_code: "cn-fj",
- count: 113
- },
- {
- type: "province",
- id: "guangdong",
- title: "Guangdong",
- parent: "chn",
- iso_code: "cn-gd",
- count: 897
- },
- {
- type: "province",
- id: "hainan",
- title: "Hainan",
- parent: "chn",
- iso_code: "cn-ha",
- count: 583
- },
- {
- type: "province",
- id: "henan",
- title: "Henan",
- parent: "chn",
- iso_code: "cn-he",
- count: 287
- },
- {
- type: "province",
- id: "jilin",
- title: "Jilin",
- parent: "chn",
- iso_code: "cn-jl",
- count: 780
- },
- // ======================================== CHINA PROVINCES END
- // ======================================== CHINA PREFECTURE START
- {
- type: "prefecture",
- id: "fujian_anqing",
- title: "Fu A Prf",
- parent: "fujian",
- count: 94237
- },
- {
- type: "prefecture",
- id: "fujian_bengbu",
- title: "Fujian Bengbu pref",
- parent: "fujian",
- count: 122
- },
- {
- type: "prefecture",
- id: "guangdong_anqing",
- title: "Guangdong Anqing pref",
- parent: "guangdong",
- count: 45
- },
- {
- type: "prefecture",
- id: "guangdong_bengbu",
- title: "Guangdong Bengbu pref",
- parent: "guangdong",
- count: 189
- },
- // ======================================== CHINA PREFECTURE END
- // ========================================= CHINA COUNTIES START
- {
- type: "county",
- id: "fujian_anqing_county_1",
- title: "Fu A Cnt",
- parent: "fujian_anqing",
- count: 94137
- },
- {
- type: "county",
- id: "fujian_anqing_county_2",
- title: "Fujian Anqing County 2",
- parent: "fujian_anqing",
- count: 12
- },
- {
- type: "county",
- id: "fujian_anqing_county_3",
- title: "Fujian Anqing_County 3",
- parent: "fujian_anqing",
- count: 13
- },
- {
- type: "county",
- id: "fujian_bengbu_county_1",
- title: "Fujian Bengbu County 1",
- parent: "fujian_bengbu",
- count: 14
- },
- {
- type: "county",
- id: "fujian_bengbu_county_2",
- title: "Fujian Bengbu County 2",
- parent: "fujian_bengbu",
- count: 15
- },
- {
- type: "county",
- id: "fujian_bengbu_county_3",
- title: "Fujian Bengbu County 3",
- parent: "fujian_bengbu",
- count: 16
- },
- {
- type: "county",
- id: "guangdong_anqing_1",
- title: "Guandong Anquing County 1",
- parent: "guangdong_anqing",
- count: 17
- },
- {
- type: "county",
- id: "guangdong_anqing_2",
- title: "Guandong Anquing County 2",
- parent: "guangdong_anqing",
- count: 18
- },
- {
- type: "county",
- id: "guangdong_bengbu_1",
- title: "Guandong Bengbu County 1",
- parent: "guangdong_bengbu",
- count: 19
- },
- {
- type: "county",
- id: "guangdong_bengbu_2",
- title: "Guandong Bengbu County 2",
- parent: "guangdong_bengbu",
- count: 20
- },
- // ========================================= CHINA COUNTIES END
- // ======================================== INDIA STATES START
- {
- type: "state",
- id: "jammu_and_kashmir",
- title: "Ja&Kash",
- parent: "ind",
- iso_code: "in-jk",
- count: 92482
- },
- {
- type: "state",
- id: "rajasthan",
- title: "Rajasthan",
- parent: "ind",
- iso_code: "in-rj",
- count: 891
- },
- {
- type: "state",
- id: "himachal_pradesh",
- title: "Himachal Pradesh",
- parent: "ind",
- iso_code: "in-hp",
- count: 459
- },
- {
- type: "state",
- id: "uttar_pradesh",
- title: "Uttar Pradesh",
- parent: "ind",
- iso_code: "in-up",
- count: 981
- },
- // ======================================== INDIA STATES END
- // ======================================== INDIAN DISTRICTS START
- {
- type: "district",
- id: "in-jk_district",
- title: "Ind Jam&Kash District",
- parent: "jammu_and_kashmir",
- count: 92481
- },
- {
- type: "district",
- id: "in-rj_district",
- title: "IndianRajast District",
- parent: "rajasthan",
- count: 18175
- },
- {
- type: "district",
- id: "in-hp_district",
- title: "IndianHimachPrad District",
- parent: "himachal_pradesh",
- count: 8175
- },
- {
- type: "district",
- id: "in-up_district",
- title: "IndianUttarPrad UttPr District",
- parent: "uttar_pradesh",
- count: 6175
- },
- // ======================================== INDIAN DISTRICTS END
- // ======================================== INDIAN DIVISIONS START
- {
- type: "division",
- id: "jammu_and_kashmir_division1",
- title: "Jam&Kash Distr division1",
- parent: "in-jk_district",
- count: 234
- },
- {
- type: "division",
- id: "jammu_and_kashmir_division2",
- title: "Jam&Kash Distr division2",
- parent: "in-jk_district",
- count: 235
- },
- {
- type: "division",
- id: "rajsthan_distr_division1",
- title: "Rajasthan Distr div1",
- parent: "in-rj_district",
- count: 135
- },
- {
- type: "division",
- id: "rajsthan_distr_division2",
- title: "Rajasthan Distr div2",
- parent: "in-rj_district",
- count: 134
- },
- {
- type: "division",
- id: "himachal_pradesh_distr_division1",
- title: "HimachPrad Distr div1",
- parent: "in-hp_district",
- count: 138
- },
- {
- type: "division",
- id: "himachal_pradesh_distr_division2",
- title: "HimachPrad Distr div2",
- parent: "in-hp_district",
- count: 139
- },
- // ======================================== INDIAN DIVISIONS END
- // ======================================== RUSSIA OBLASTI START
- {
- type: "federal_region",
- id: "amurskaya",
- title: "Амурская область",
- parent: "ru",
- iso_code: "ru-am",
- count: 55054
- },
- {
- type: "federal_region",
- id: "arhangelskaya",
- title: "Архангельская область",
- parent: "ru",
- iso_code: "ru-ar",
- count: 1064
- },
- {
- type: "federal_region",
- id: "astrahanskaya",
- title: "Астраханская область",
- parent: "ru",
- iso_code: "ru-as",
- count: 1084
- },
- {
- type: "federal_region",
- id: "belgorodskaya",
- title: "Белгородская область",
- parent: "ru",
- iso_code: "ru-bl",
- count: 1084
- }
- // ======================================== RUSSIA OBLASTI END
- ];
- nodes = [];
- class Node {
- constructor(model) {
- this.model = model;
- this.parent = null;
- this.children = [];
- }
- }
- for (let i = 0; i < regions.length; i++) {
- nodes[regions[i].id] = new Node(regions[i]);
- }
- for (let i = 0; i < regions.length; i++) {
- if (regions[i].parent) {
- nodes[regions[i].parent].children.push(regions[i].id);
- }
- }
- const fill_children = parent => {
- if (parent && parent.children) {
- for (let i = 0; i < parent.children.length; i++) {
- fill_children(nodes[parent.children[i]]);
- }
- for (let i = 0; i < parent.children.length; i++) {
- nodes[parent.children[i]].parent = parent;
- parent.children[i] = nodes[parent.children[i]];
- delete nodes[parent.children[i].model.id];
- }
- }
- };
- Object.keys(nodes).map(id => {
- fill_children(nodes[id]);
- });
- console.log(Object.values(nodes))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement