deep-object-diff
                                
                                 deep-object-diff copied to clipboard
                                
                                    deep-object-diff copied to clipboard
                            
                            
                            
                        The array detailedDiff does not work
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?
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.