Last active
February 4, 2021 15:55
-
-
Save mpelzsherman/ad1cbd2eee49c8d577f7b9bd960bc13a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example shows that deep-diff reports arrays of objects with different sort order as "edit" diffs: | |
var diff = require('deep-diff').diff; | |
var lhs = { | |
name: 'my object', | |
details: { | |
it: 'has', | |
an: 'array', | |
with: [{'a': 1}, {'a': 2}, {'a': 3}] | |
} | |
}; | |
var rhs = { | |
name: 'my object', | |
details: { | |
with: [{'a': 3}, {'a': 2}, {'a': 1}], | |
it: 'has', | |
an: 'array', | |
} | |
}; | |
var differences = diff(lhs, rhs); | |
console.log(JSON.stringify(differences, null, 2)); | |
❯ node diff.js | |
[ | |
{ | |
"kind": "E", | |
"path": [ | |
"details", | |
"with", | |
2, | |
"a" | |
], | |
"lhs": 3, | |
"rhs": 1 | |
}, | |
{ | |
"kind": "E", | |
"path": [ | |
"details", | |
"with", | |
0, | |
"a" | |
], | |
"lhs": 1, | |
"rhs": 3 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment