function Dijkstra(G, s, t) {
  let left = [];

  G.nodes.forEach(function(node) {
    node.dist = Infinity;
    node.parent = null;
    left.push(node);
  });

  s.dist = 0;

  while(left.length !== 0) {
    left.sort((a, b) => (a.dist - b.dist));
    let current = left.shift();
    if (current.equals(t)) {
      return t;
    }

    let adjacent = G.getAdjacentNodes(current);
    adjacent.forEach(function(node) {
      let newDist = current.dist + W(current, node);
      if (newDist < node.dist) {
        node.dist = newDist;
        node.parent = current;
      }
    });
  }
}