X Tutup
The Wayback Machine - https://web.archive.org/web/20201112181103/https://github.com/mattphillips/deep-object-diff/pull/49
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NaN value #49

Open
wants to merge 3 commits into
base: master
from
Open

Conversation

@Leomaradan
Copy link

@Leomaradan Leomaradan commented Aug 15, 2019

NaN cannot be checked as equality. This commit add a test based on isNaN

nikolayg and others added 2 commits Jul 12, 2019
NaN cannot be checked as equality. This commit add a test based on isNaN
@coveralls
Copy link

@coveralls coveralls commented Aug 15, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 1e9c938 on Leomaradan:master into 6296889 on mattphillips:master.

Typescript definitions
Copy link

@anko anko left a comment

Just some thoughts.

@@ -173,5 +174,15 @@ describe('.diff', () => {
expect(diff(lhs, rhs)).toEqual({ b: 2 });
});
});

describe('nested NaN', () => {
test('returns empty object when there is nested NaN value', () => {

This comment has been minimized.

@anko

anko Jan 7, 2020

This test description confused me.

More concrete wording:

Suggested change
test('returns empty object when there is nested NaN value', () => {
test('treats NaN -> NaN as unchanged', () => {
@@ -3,6 +3,10 @@ import { isDate, isEmpty, isObject, properObject } from '../utils';
const diff = (lhs, rhs) => {
if (lhs === rhs) return {}; // equal return no diff

if (typeof lhs === "number" && typeof rhs === "number") {
if (isNaN(lhs) && isNaN(rhs)) return {}; // NaN is equal
}

This comment has been minimized.

@anko

anko Jan 7, 2020

Could use Number.isNaN to check both Number type and NaN value simultaneously.

-   if (typeof lhs === "number" && typeof rhs === "number") {
-     if (isNaN(lhs) && isNaN(rhs)) return {}; // NaN is equal
-  }
+   if (Number.isNan(lhs) && Number.isNan(rhs)) return {}; // NaN is equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.
X Tutup