Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.05 KB | None | 0 0
  1. regions = [
  2. // ======================================== REGIONS START
  3. {
  4. type: "region",
  5. id: "3128",
  6. title: "Africa and Middle East",
  7. parent: null,
  8. count: 15945
  9. },
  10. {
  11. type: "region",
  12. id: "3122",
  13. title: "AsiaAsiaAsia Pacific",
  14. parent: null,
  15. count: 789643
  16. },
  17. {
  18. type: "region",
  19. id: "3123",
  20. title: "Australia and Oceania",
  21. parent: null,
  22. count: 54589
  23. },
  24. {
  25. type: "region",
  26. id: "3114",
  27. title: "Europe and Central Asia",
  28. parent: null,
  29. count: 94589
  30. },
  31. {
  32. type: "region",
  33. id: "3132",
  34. title: "North and South America",
  35. parent: null,
  36. count: 18754
  37. },
  38. // ======================================== REGIONS END
  39.  
  40. // ======================================== AFRICA_AND_MIDDLE_EAST COUNTRIES START
  41. {
  42. type: "country",
  43. id: "algeria",
  44. title: "Algeria",
  45. parent: "3128",
  46. iso_code: "DZ",
  47. count: 1834
  48. },
  49. {
  50. type: "country",
  51. id: "libya",
  52. title: "Libya",
  53. parent: "3128",
  54. iso_code: "LY",
  55. count: 1673
  56. },
  57. {
  58. type: "country",
  59. id: "egypt",
  60. title: "Egypt",
  61. parent: "3128",
  62. iso_code: "EG",
  63. count: 1931
  64. },
  65. {
  66. type: "country",
  67. id: "morocco",
  68. title: "Morocco",
  69. parent: "3128",
  70. iso_code: "MA",
  71. count: 2145
  72. },
  73. // ======================================== AFRICA_AND_MIDDLE_EAST COUNTRIES END
  74.  
  75. // ======================================== ASIA_PACIFIC COUNTRIES START
  76. {
  77. type: "country",
  78. id: "ind",
  79. title: "India",
  80. parent: "3122",
  81. iso_code: "IN",
  82. count: 1956
  83. },
  84. {
  85. type: "country",
  86. id: "pakistan",
  87. title: "Pakistan",
  88. parent: "3122",
  89. iso_code: "PK",
  90. count: 2374
  91. },
  92. {
  93. type: "country",
  94. id: "chn",
  95. title: "China",
  96. parent: "3122",
  97. iso_code: "CN",
  98. count: 254789
  99. },
  100. {
  101. type: "country",
  102. id: "nepal",
  103. title: "Nepal",
  104. parent: "3122",
  105. iso_code: "NP",
  106. count: 1587
  107. },
  108. // ======================================== ASIA_PACIFIC COUNTRIES START END
  109.  
  110. // ======================================== AUSTRALIA_AND_OCEANIA COUNTRIES START
  111. {
  112. type: "country",
  113. id: "australia",
  114. title: "Australia",
  115. parent: "3123",
  116. iso_code: "AU",
  117. count: 41587
  118. },
  119. {
  120. type: "country",
  121. id: "new_zeland",
  122. title: "New Zeland",
  123. parent: "3123",
  124. iso_code: "NZ",
  125. count: 11183
  126. },
  127. {
  128. type: "country",
  129. id: "papua_new_guinea",
  130. title: "Papua New Guinea",
  131. parent: "3123",
  132. iso_code: "PG",
  133. count: 24981
  134. },
  135. {
  136. type: "country",
  137. id: "solomon_islands",
  138. title: "Solomon Islands",
  139. parent: "3123",
  140. iso_code: "SB",
  141. count: 10935
  142. },
  143. // ======================================== AUSTRALIA_AND_OCEANIA COUNTRIES END
  144.  
  145. // ======================================== EUROPE_AND_CENTRAL_ASIA COUNTRIES START
  146. {
  147. type: "country",
  148. id: "ru",
  149. title: "Russia",
  150. parent: "3114",
  151. iso_code: "RU",
  152. count: 148502
  153. },
  154. {
  155. type: "country",
  156. id: "belarus",
  157. title: "Belarus",
  158. parent: "3114",
  159. iso_code: "BY",
  160. count: 24154
  161. },
  162. {
  163. type: "country",
  164. id: "poland",
  165. title: "Poland",
  166. parent: "3114",
  167. iso_code: "PL",
  168. count: 24154
  169. },
  170. {
  171. type: "country",
  172. id: "kazakhstan",
  173. title: "Kazakhstan",
  174. parent: "3114",
  175. iso_code: "KZ",
  176. count: 48917
  177. },
  178. // ======================================== EUROPE_AND_CENTRAL_ASIA COUNTRIES END
  179.  
  180. // ======================================== NORTH_AND_SOUTH_AMERICA COUNTRIES START
  181. {
  182. type: "country",
  183. id: "canada",
  184. title: "Canada",
  185. parent: "3132",
  186. iso_code: "CA",
  187. count: 87917
  188. },
  189. {
  190. type: "country",
  191. id: "united_states",
  192. title: "United States of America",
  193. parent: "3132",
  194. iso_code: "US",
  195. count: 24887
  196. },
  197. {
  198. type: "country",
  199. id: "brazil",
  200. title: "Brazil",
  201. parent: "3132",
  202. iso_code: "BR",
  203. count: 46357
  204. },
  205. {
  206. type: "country",
  207. id: "argentina",
  208. title: "Argentina",
  209. parent: "3132",
  210. iso_code: "AR",
  211. count: 21036
  212. },
  213. // ======================================== NORTH_AND_SOUTH_AMERICA COUNTRIES END
  214.  
  215. // ======================================== CHINA PROVINCES START
  216. {
  217. type: "province",
  218. id: "xinjiang",
  219. title: "Xinjiang",
  220. parent: "chn",
  221. iso_code: "cn-xj",
  222. count: 234
  223. },
  224. {
  225. type: "province",
  226. id: "qinghai",
  227. title: "Qinghai",
  228. parent: "chn",
  229. iso_code: "cn-qh",
  230. count: 942
  231. },
  232. {
  233. type: "province",
  234. id: "yunnan",
  235. title: "Yunnan",
  236. parent: "chn",
  237. iso_code: "cn-yn",
  238. count: 821
  239. },
  240. {
  241. type: "province",
  242. id: "hunan",
  243. title: "Hunan",
  244. parent: "chn",
  245. iso_code: "cn-hn",
  246. count: 744
  247. },
  248. {
  249. type: "province",
  250. id: "fujian",
  251. title: "Fujian",
  252. parent: "chn",
  253. iso_code: "cn-fj",
  254. count: 113
  255. },
  256. {
  257. type: "province",
  258. id: "guangdong",
  259. title: "Guangdong",
  260. parent: "chn",
  261. iso_code: "cn-gd",
  262. count: 897
  263. },
  264. {
  265. type: "province",
  266. id: "hainan",
  267. title: "Hainan",
  268. parent: "chn",
  269. iso_code: "cn-ha",
  270. count: 583
  271. },
  272. {
  273. type: "province",
  274. id: "henan",
  275. title: "Henan",
  276. parent: "chn",
  277. iso_code: "cn-he",
  278. count: 287
  279. },
  280. {
  281. type: "province",
  282. id: "jilin",
  283. title: "Jilin",
  284. parent: "chn",
  285. iso_code: "cn-jl",
  286. count: 780
  287. },
  288. // ======================================== CHINA PROVINCES END
  289.  
  290. // ======================================== CHINA PREFECTURE START
  291. {
  292. type: "prefecture",
  293. id: "fujian_anqing",
  294. title: "Fu A Prf",
  295. parent: "fujian",
  296. count: 94237
  297. },
  298. {
  299. type: "prefecture",
  300. id: "fujian_bengbu",
  301. title: "Fujian Bengbu pref",
  302. parent: "fujian",
  303. count: 122
  304. },
  305. {
  306. type: "prefecture",
  307. id: "guangdong_anqing",
  308. title: "Guangdong Anqing pref",
  309. parent: "guangdong",
  310. count: 45
  311. },
  312. {
  313. type: "prefecture",
  314. id: "guangdong_bengbu",
  315. title: "Guangdong Bengbu pref",
  316. parent: "guangdong",
  317. count: 189
  318. },
  319. // ======================================== CHINA PREFECTURE END
  320.  
  321. // ========================================= CHINA COUNTIES START
  322. {
  323. type: "county",
  324. id: "fujian_anqing_county_1",
  325. title: "Fu A Cnt",
  326. parent: "fujian_anqing",
  327. count: 94137
  328. },
  329. {
  330. type: "county",
  331. id: "fujian_anqing_county_2",
  332. title: "Fujian Anqing County 2",
  333. parent: "fujian_anqing",
  334. count: 12
  335. },
  336. {
  337. type: "county",
  338. id: "fujian_anqing_county_3",
  339. title: "Fujian Anqing_County 3",
  340. parent: "fujian_anqing",
  341. count: 13
  342. },
  343. {
  344. type: "county",
  345. id: "fujian_bengbu_county_1",
  346. title: "Fujian Bengbu County 1",
  347. parent: "fujian_bengbu",
  348. count: 14
  349. },
  350. {
  351. type: "county",
  352. id: "fujian_bengbu_county_2",
  353. title: "Fujian Bengbu County 2",
  354. parent: "fujian_bengbu",
  355. count: 15
  356. },
  357. {
  358. type: "county",
  359. id: "fujian_bengbu_county_3",
  360. title: "Fujian Bengbu County 3",
  361. parent: "fujian_bengbu",
  362. count: 16
  363. },
  364. {
  365. type: "county",
  366. id: "guangdong_anqing_1",
  367. title: "Guandong Anquing County 1",
  368. parent: "guangdong_anqing",
  369. count: 17
  370. },
  371. {
  372. type: "county",
  373. id: "guangdong_anqing_2",
  374. title: "Guandong Anquing County 2",
  375. parent: "guangdong_anqing",
  376. count: 18
  377. },
  378. {
  379. type: "county",
  380. id: "guangdong_bengbu_1",
  381. title: "Guandong Bengbu County 1",
  382. parent: "guangdong_bengbu",
  383. count: 19
  384. },
  385. {
  386. type: "county",
  387. id: "guangdong_bengbu_2",
  388. title: "Guandong Bengbu County 2",
  389. parent: "guangdong_bengbu",
  390. count: 20
  391. },
  392. // ========================================= CHINA COUNTIES END
  393.  
  394. // ======================================== INDIA STATES START
  395. {
  396. type: "state",
  397. id: "jammu_and_kashmir",
  398. title: "Ja&Kash",
  399. parent: "ind",
  400. iso_code: "in-jk",
  401. count: 92482
  402. },
  403. {
  404. type: "state",
  405. id: "rajasthan",
  406. title: "Rajasthan",
  407. parent: "ind",
  408. iso_code: "in-rj",
  409. count: 891
  410. },
  411. {
  412. type: "state",
  413. id: "himachal_pradesh",
  414. title: "Himachal Pradesh",
  415. parent: "ind",
  416. iso_code: "in-hp",
  417. count: 459
  418. },
  419. {
  420. type: "state",
  421. id: "uttar_pradesh",
  422. title: "Uttar Pradesh",
  423. parent: "ind",
  424. iso_code: "in-up",
  425. count: 981
  426. },
  427. // ======================================== INDIA STATES END
  428.  
  429. // ======================================== INDIAN DISTRICTS START
  430. {
  431. type: "district",
  432. id: "in-jk_district",
  433. title: "Ind Jam&Kash District",
  434. parent: "jammu_and_kashmir",
  435. count: 92481
  436. },
  437. {
  438. type: "district",
  439. id: "in-rj_district",
  440. title: "IndianRajast District",
  441. parent: "rajasthan",
  442. count: 18175
  443. },
  444. {
  445. type: "district",
  446. id: "in-hp_district",
  447. title: "IndianHimachPrad District",
  448. parent: "himachal_pradesh",
  449. count: 8175
  450. },
  451. {
  452. type: "district",
  453. id: "in-up_district",
  454. title: "IndianUttarPrad UttPr District",
  455. parent: "uttar_pradesh",
  456. count: 6175
  457. },
  458. // ======================================== INDIAN DISTRICTS END
  459.  
  460. // ======================================== INDIAN DIVISIONS START
  461. {
  462. type: "division",
  463. id: "jammu_and_kashmir_division1",
  464. title: "Jam&Kash Distr division1",
  465. parent: "in-jk_district",
  466. count: 234
  467. },
  468. {
  469. type: "division",
  470. id: "jammu_and_kashmir_division2",
  471. title: "Jam&Kash Distr division2",
  472. parent: "in-jk_district",
  473. count: 235
  474. },
  475. {
  476. type: "division",
  477. id: "rajsthan_distr_division1",
  478. title: "Rajasthan Distr div1",
  479. parent: "in-rj_district",
  480. count: 135
  481. },
  482. {
  483. type: "division",
  484. id: "rajsthan_distr_division2",
  485. title: "Rajasthan Distr div2",
  486. parent: "in-rj_district",
  487. count: 134
  488. },
  489. {
  490. type: "division",
  491. id: "himachal_pradesh_distr_division1",
  492. title: "HimachPrad Distr div1",
  493. parent: "in-hp_district",
  494. count: 138
  495. },
  496. {
  497. type: "division",
  498. id: "himachal_pradesh_distr_division2",
  499. title: "HimachPrad Distr div2",
  500. parent: "in-hp_district",
  501. count: 139
  502. },
  503. // ======================================== INDIAN DIVISIONS END
  504.  
  505. // ======================================== RUSSIA OBLASTI START
  506. {
  507. type: "federal_region",
  508. id: "amurskaya",
  509. title: "Амурская область",
  510. parent: "ru",
  511. iso_code: "ru-am",
  512. count: 55054
  513. },
  514. {
  515. type: "federal_region",
  516. id: "arhangelskaya",
  517. title: "Архангельская область",
  518. parent: "ru",
  519. iso_code: "ru-ar",
  520. count: 1064
  521. },
  522. {
  523. type: "federal_region",
  524. id: "astrahanskaya",
  525. title: "Астраханская область",
  526. parent: "ru",
  527. iso_code: "ru-as",
  528. count: 1084
  529. },
  530. {
  531. type: "federal_region",
  532. id: "belgorodskaya",
  533. title: "Белгородская область",
  534. parent: "ru",
  535. iso_code: "ru-bl",
  536. count: 1084
  537. }
  538. // ======================================== RUSSIA OBLASTI END
  539. ];
  540.  
  541.  
  542.  
  543. nodes = [];
  544.  
  545. class Node {
  546. constructor(model) {
  547. this.model = model;
  548. this.parent = null;
  549. this.children = [];
  550. }
  551. }
  552.  
  553. for (let i = 0; i < regions.length; i++) {
  554. nodes[regions[i].id] = new Node(regions[i]);
  555. }
  556.  
  557. for (let i = 0; i < regions.length; i++) {
  558. if (regions[i].parent) {
  559. nodes[regions[i].parent].children.push(regions[i].id);
  560. }
  561. }
  562.  
  563. const fill_children = parent => {
  564. if (parent && parent.children) {
  565. for (let i = 0; i < parent.children.length; i++) {
  566. fill_children(nodes[parent.children[i]]);
  567. }
  568.  
  569. for (let i = 0; i < parent.children.length; i++) {
  570. nodes[parent.children[i]].parent = parent;
  571. parent.children[i] = nodes[parent.children[i]];
  572. delete nodes[parent.children[i].model.id];
  573. }
  574. }
  575. };
  576.  
  577. Object.keys(nodes).map(id => {
  578. fill_children(nodes[id]);
  579. });
  580.  
  581. console.log(Object.values(nodes))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement