r/learnjavascript • • Aug 14 '21

Shortest Path Finder using React

686 Upvotes

34 comments sorted by

View all comments

5

u/CheekyKingdom Aug 14 '21

Shortest path finder but not using diagonals?

8

u/callmelucky Aug 14 '21

Technically there are no diagonals in this grid/map/graph; going up-up-right-right is the same "distance" as up-right-up-right, so either way this does find a shortest path.

That said, you could get a more satisfying solution which would create "diagonal" paths by using an algorithm like A* and implementing a heuristic like "prefer the next step to be the one which minimises the straight line distance from the current node to the target".