Kruskal implementation with javascript