DEV Community

Discussion on: Simplest way to compare two numbers array in JS

Collapse
 
hnicolas profile image
Nicolas Hervé

It don"t work with duplicated values.

arrayEqualUnsorted([1, 1, 2], [1, 2, 2]); // true
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hongphuc5497 profile image
Hong Phuc

You should remove duplicated items with Set class first before comparing, for example:

const uniqueArr = [... new Set(yourArr)]