I have an array of float elements and I’m trying to remove elements that are close to each other.
I.e. if there are two elements less than 0.4 apart (e.g. 15.1 and 15.3), I want to remove the second one. The 0.4 should be the input parameter for the algorithm.
The array is already sorted in a specific order (not ascending/descending) and I need to preserve that order.
I have created an
ApproximateFloatComparerclass as follows:Then create a method to deduplicate:
Then combine it all: