Javascript implementation of A* search