Using JavaScript, I’d like to split one big array of coordinates into smaller arrays based on coinciding points. I am not 100% sure how to write the following in code but it describes what I’m attempting to achieve:
-
Iterate through the array
var A = [(1,2)(1,3)(2,3)(9,10)(9,11)(10,11)]; -
Combine the pairs that contain any matching/identical coordinate points:
var B = (1,2)(1,3)(2,3)var C = (9,10)(9,11)(10,11) -
Combine the matching/identical points and create new, smaller arrays from the combinations in point #2
var D = [1,2,3]var E = [9,10,11]
Can I get help please?
Working answer: http://jsfiddle.net/y3h9L/
OK, so if I understand the requirement A is a one-dimensional array that is assumed to have an even number of elements in x,y pairs.
I’ve made no effort to pretty-up or optimise the following code, but it works:
If it’s not obvious how this works, follow it through with a debugger and/or pencil and paper.