Skip to content

Commit ecd99c9

Browse files
committed
Fix issue in dijkstra for empty matrix
1 parent e59c2d9 commit ecd99c9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎src/graphs/shortest-path/dijkstra.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@
112112
visited[current.node] = true;
113113
current = unvisited.extract();
114114
}
115-
return distance[dest].distance;
115+
if (distance[dest]) {
116+
return distance[dest].distance || Infinity;
117+
}
118+
return Infinity;
116119
};
117120

118121
})();

0 commit comments

Comments
 (0)