Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const roads = [
- "Дом Алисы-Дом Боба",
- "Дом Алисы-Почта",
- "Дом Дарии-Дом Эрни",
- "Дом Эрни-Дом Греты",
- "Дом Греты-Магазин",
- "Рынок-Почта",
- "Рынок-Ратуша",
- "Дом Алисы-Склад",
- "Дом Боба-Ратуша",
- "Дом Дарии-Ратуша",
- "Дом Греты-Ферма",
- "Рынок-Магазин",
- "Магазин-Ратуша"
- ];
- //console.log( roads[0].split("-") );
- function ccc( edges ) {
- let graphhh = Object.create( null );
- function sss( from, to ) {
- if ( graphhh[ from ] == null ) {
- graphhh[ from ] = [ to ];
- console.log( graphhh );
- } else {
- graphhh[from].push( to );
- }
- }
- for ( let [ from, to ] of edges.map( r => r.split("-") ) ) {
- sss( from, to );
- sss( to, from );
- }
- return graphhh;
- }
- const roadGraph = ccc( roads );
Advertisement
Add Comment
Please, Sign In to add comment