Testing equality of vectors in a 2 dimensional array

That keyword this inside the callback removeIfSameVec(vec, idx, arr) refers to the 2nd parameter from method Array::some(callbackFn, thisArg):

So it’s comparing each p5.Vector object from vecRowTwo[] cloned array to the current p5.Vector object (represented by loop’s iterator vecOne) from vecRowOne[] array.

If they’re equals(), I use Array::splice(startIndex, deleteCount) method to delete the current index from vecRowTwo[] cloned array (represented by callback’s parameter arr) to make sure that p5.Vector isn’t found again for the rest of the loop:

At the end of the loop it’s expected for vecRowTwo[] cloned array to be empty (its length = 0):

If so, it means that each p5.Vector object from vecRowOne[] array has found an equals() among vecRowTwo[] cloned array.

1 Like