-
Notifications
You must be signed in to change notification settings - Fork 20
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 numeric and json diff #16
Conversation
js/json.ts
Outdated
} | ||
|
||
function isArray(obj: any): obj is Array<unknown> { | ||
return "[object Array]" === Object.prototype.toString.call(obj); |
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.
Why not use obj instance of Array
as is done in replacer
?
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.
Similarly for isObject
: obj instanceof Object and !isArray(obj)
js/json.ts
Outdated
|
||
// https://gist.github.com/davidfurlong/463a83a33b70a3b6618e97ec9679e490 | ||
const replacer = (key: string, value: any) => | ||
value instanceof Object && !(value instanceof Array) |
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.
equivalent to isObject
?
js/number.ts
Outdated
output === 0 && expected === 0 | ||
? 1 | ||
: 1 - | ||
Math.abs(expected - output) / |
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 quotient will exceed 1 if the signs of expected and output are different. A simple solution would be to multiply the denominator by 2.
Looks good thanks for doing this sir |
This PR adds support for a few planned diff functions:
NumericDiff
compares numbers and returns a score that's 1 - the % difference between the two numbersJSONDiff
recursively compares json objects, using a provided string and numeric scorer, falling back to string comparison if the object types don't match.