1loc icon indicating copy to clipboard operation
1loc copied to clipboard

Compare two arrays regardless of order is simply incorrect

Open secondfry opened this issue 3 years ago • 0 comments

https://github.com/1milligram/1loc/blob/cecbfa239c1d6c9d527518c157b9ea20c4140c9b/snippets/array/compare-two-arrays-regardless-of-order.md?plain=1#L10

The Set object lets you store unique values of any type, whether primitive values or object references.

And an array can have duplicate values.

So it fails simplest of tests: isEqual([1], [1, 1]); Checking for length would be incorrect too, consider such case: isEqual([1, 1, 2], [1, 2, 2]);

Also concerns from #414.

And lastly one should keep in mind that:

const a = {a: 1};
const b = {...a};
a !== b; // true

Maybe it should be documented on equality function page.

secondfry avatar Jun 18 '22 17:06 secondfry