JavaScript code for Quick union, find