Here is the code for A* Algorithm in JavaScript:
index.tsx1269 chars47 lines
To use this algorithm, you need to provide the start
and goal
nodes, and a graph
which is represented by a Map
where the keys are nodes and the values are arrays of neighboring nodes.
For example:
index.tsx235 chars9 lines
In this example, the graph looks like this:
index.tsx34 chars4 lines
And the shortest path from A to E is A -> B -> C -> E.
gistlibby LogSnag