DEV Community

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

Collapse
 
0shuvo0 profile image
Shuvo

And your function has some drawbacks also
algo fail

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Whether that's a drawback or by design is questionable; whether two identical objects should be treated as actually the same completely depends on your problem domain.

Thread Thread
 
0shuvo0 profile image
Shuvo

agreed 100%

Collapse
 
ksengine profile image
Kavindu Santhusa

In js your Objects are not equal
If your arrays are

const num5 = { num: 5 };
const array1 = [1, 2, 3, 4, num5];
const array2 = [1, 2, 3, 4, num5];
Enter fullscreen mode Exit fullscreen mode

It works.