Guest User

Untitled

a guest
Apr 26th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const roads = [
  2.   "Дом Алисы-Дом Боба",
  3.   "Дом Алисы-Почта",
  4.   "Дом Дарии-Дом Эрни",
  5.   "Дом Эрни-Дом Греты",
  6.   "Дом Греты-Магазин",
  7.   "Рынок-Почта",
  8.   "Рынок-Ратуша",
  9.   "Дом Алисы-Склад",
  10.   "Дом Боба-Ратуша",
  11.   "Дом Дарии-Ратуша",
  12.   "Дом Греты-Ферма",
  13.   "Рынок-Магазин",
  14.   "Магазин-Ратуша"
  15. ];
  16. //console.log( roads[0].split("-") );
  17. function ccc(edges) {
  18.   let graphhh = Object.create({});
  19.   function sss(from, to) {
  20.     if (graphhh[from] == null) {
  21.       graphhh[from] = [to];
  22.       console.log(graphhh);
  23.     } else {
  24.       graphhh[from].push(to);
  25.     }
  26.   }
  27.   for (let [from, to] of edges.map(r => r.split("-"))) {
  28.     sss(from, to);
  29.     sss(to, from);
  30.   }
  31.   return graphhh;
  32. }
  33.  
  34. const roadGraph = ccc(roads);
  35. //console.log( roadGraph[ roads[0].split("-")[0] ] )
Advertisement
Add Comment
Please, Sign In to add comment