Skip to content

Instantly share code, notes, and snippets.

@mpelzsherman
Last active February 4, 2021 15:55
Show Gist options
  • Save mpelzsherman/ad1cbd2eee49c8d577f7b9bd960bc13a to your computer and use it in GitHub Desktop.
Save mpelzsherman/ad1cbd2eee49c8d577f7b9bd960bc13a to your computer and use it in GitHub Desktop.
// 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