Skip to content

Wrong Output when something is added at front and deleted in between  #44

Description

@siddharth232
const oldValue = [
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 10,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 10,
    },
    {
      Details: [{
        Amount: 110,
        CurrencyCode: 'USD',
        Quantity: 16,
        RegisteredPrice: 20,
        id: 20,
      }],
      Type: 'Type-11',
      Product: 'Product-11',
      id: 20,
    },
    {
      Details: [{
        Amount: 120,
        CurrencyCode: 'USD',
        Quantity: 17,
        RegisteredPrice: 20,
        id: 30,
      }],
      Type: 'Type-12',
      Product: 'Product-12',
      id: 30,
    },
  ];
  const newValue = [
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 40,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 40,
    },
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 10,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 10,
    },
    {
      Details: [{
        Amount: 120,
        CurrencyCode: 'USD',
        Quantity: 17,
        RegisteredPrice: 20,
        id: 30,
      }],
      Type: 'Type-12',
      Product: 'Product-12',
      id: 30,
    },
  ];
function hashFn(x) {
    return x.id;
}
console.log(jiff.diff(oldValue,newValue,{hash: hashFn,invertible:false}));

Output:
[ { op: 'add', path: '/0', value: { Details: [Array], Type: 'Variable', Product: 'NaN', id: 40 }, context: undefined }, { op: 'remove', path: '/2', context: undefined } ]

Expected:
[ { op: 'add', path: '/0', value: { Details: [Array], Type: 'Variable', Product: 'NaN', id: 40 }, context: undefined }, { op: 'remove', path: '/1', context: undefined } ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions