Solution: lb_pathfinder

JavaScript·1 min read·Apr 22, 2025

Here is the commented solution for this project.

Create the script

Create a file named lb_pathfinder.js.

$ touch lb_pathfinder.js

Set up variables

The objective of this part is to declare and initialize all the variables needed to calculate distances and record the best path between cities.

Declare a function named findShortestPath.

lb_pathfinder.js
function findShortestPath(graph, startCity, targetCity) {  //}

Declare a variable named distances to store the shortest known distances from the start city and initialize it with an empty object literal.

lb_pathfinder.js
function findShortestPath(graph, startCity, targetCity) {  const distances = {};}