The problem
In lua I have an array of values (specifically - x and y position values) from which I would like to remove duplicate pairs. The array looks as follows:
array = {x1, y1, x2, y2, x3, y3, ... , xn, yn}
where n is the number of corrdinates pairs. So whether a value is an x coordinate or y coordinate is determined solely by its position in the array. A duplicate is defined as xa == xb and ya == yb. So for example if x1 == x2 and y1 == y2 I would like to remove x1 and y1 or (not both) x2 and y2 from the array.
Questions
- How could one remove duplicates from such array?
- Could it be done without subdividing the array?
- Bonus: In more general case what if array contained 3 (or even more) variables, that is
array = {x1, y1, z1, x2, y2, z2, ... , xn, yn, zn}
Numeric example
If an array of values is given:
array = {1, 1, 2, 1, 1, 1, 2, 1}
then removing duplicates should result in an array:
array = {1, 1, 2, 1}