fast-deep-equal icon indicating copy to clipboard operation
fast-deep-equal copied to clipboard

Feature request: ignore undefined values

Open tmtron opened this issue 2 years ago • 2 comments

in version 3.1.3 of the library the following comparison returns false

equal({ a: undefined }, {})

That's quite a surprise for me, but since there are test-cases for this case, I guess it works as expected.

It would be good to have an option to ignore undefined values.

tmtron avatar Aug 04 '21 15:08 tmtron

This comparison has to be falsy since your second object does not contain the a property, its working as intended imo.

dalepo avatar Apr 10 '22 23:04 dalepo

Yes, technically they are different, but semantically they may be equal: i.e. a missing property and a property with the value undefined often mean the same thing: For example, look at the output of JSON.stringify()

  • JSON.stringify({}) = {}
  • JSON.stringify({a:undefined}) = {}

The result is the same. So in this case, so equals should return true.

tmtron avatar Apr 11 '22 06:04 tmtron