Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for NaN value #49
Conversation
NaN cannot be checked as equality. This commit add a test based on isNaN
Typescript definitions
|
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', () => { | |||
anko
Jan 7, 2020
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 | |||
| } | |||
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
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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