Skip to content
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

The array detailedDiff does not work #51

Open
mtermoul opened this issue Nov 6, 2019 · 1 comment
Open

The array detailedDiff does not work #51

mtermoul opened this issue Nov 6, 2019 · 1 comment

Comments

@mtermoul
Copy link

mtermoul commented Nov 6, 2019

I am just trying this library for simple arrays and it's not working as I expected. This is the code:

const a1 = [2, 5, 8, 20];
const a2 = [5, 7, 9, 20];
const diff = detailedDiff(a1, a2);
// this is the result
// { added: {},
//   deleted: {},
//  updated: {0: 5, 1: 7, 2: 9} }

// I was expecting this result
// { added: {0: 7, 1: 9}
// deleted: {0: 2, 1: 8}
// updated: {}}

Can someone explain this result?

@anko
Copy link
Contributor

anko commented Nov 12, 2019

It's because the keys of your 4-element array are the indexes 0–3, and none of them go away, they just change to contain different values.

In other words, the sequence of operations to get from [2, 5, 8, 20] to [5, 7, 9, 20] is—

a[0] = 5
a[1] = 7
a[2] = 9

—all of which are updates to existing indexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants