I am making a program that solves a puzzle game, and it finds all the possible moves on a board and puts all the possible resulting boards in an object. Then it finds all the po
I don't have a JavaScript description but i would generally do it by keeping a queue of unexplored nodes.
Also there is some pseudopod on the Wikipedia page as well as some more explanations HERE
Also a quick Google search turned up a similar algorithm that could be bent to your purpose HERE