Skip to content

Instantly share code, notes, and snippets.

View tternquist's full-sized avatar

Tom Ternquist tternquist

View GitHub Profile
@tternquist
tternquist / shortestPath.sjs
Last active November 12, 2021 21:14
Shortest Path (Javascript)
function shortestPath(adjList, v, goal) {
var visited = []
var queue = [];
var shortestDistance = {};
var distance = {}
var adjListKeys = Object.keys(adjList);
for (var i = 0; i < adjListKeys.length; i++) {
var node = adjListKeys[i];
if (node !== v.toString()) {
shortestDistance[node] = -1;