(points)
| 20 | }) |
| 21 | |
| 22 | const buildGraph = (points) => { |
| 23 | const { graph, seen, minHeap } = initGraph(points); |
| 24 | |
| 25 | for (let src = 0; src < (points.length - 1); src++) { |
| 26 | for (let dst = (src + 1); (dst < points.length); dst++) { |
| 27 | const cost = getCost(points, src, dst); |
| 28 | |
| 29 | graph[src].push([ dst, cost ]); |
| 30 | graph[dst].push([ src, cost ]); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | const [ src, cost, priority ] = [ 0, 0, 0 ]; |
| 35 | const node = [ src, cost ]; |
| 36 | |
| 37 | minHeap.enqueue(node, priority); |
| 38 | |
| 39 | return { graph, seen, minHeap }; |
| 40 | } |
| 41 | |
| 42 | const getCost = (points, src, dst) => { |
| 43 | const [ [ x1, y1 ], [ x2, y2 ] ] = [ points[src], points[dst] ]; |
no test coverage detected