A JavaScript implementation of the union find algorithm