First, start your inner loop at i + 1
. You've already compared elements up to i
, so there's no need to repeat, right? That let's you get rid of your if
statement as well.
Then, when you splice, decrement j
so as to not skip the next element.
for(var i = 0; i < points.length; i++) {
for(var j = i + 1; j < points.length ; j++) {
if (distance(i, j) < 10) {
points.splice(j--, 1);
}
}
}