Javascript best - first search.