-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: main
Are you sure you want to change the base?
Conversation
NaN cannot be checked as equality. This commit add a test based on isNaN
Typescript definitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test description confused me.
More concrete wording:
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 | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anko you meant to cap the last 'n' --> Number.isNaN
NaN cannot be checked as equality. This commit add a test based on isNaN