-1

I'm fetching data from a soccer live API every minute using AWS for automation. I'd like to compare the new data with the old one. Each piece of data is an Array, so two JavaScript Arrays will be compared.

If there is a change in a new value, this value will be shown to the user at the Vue.js front-end. For example, the user will be alerted when shot on target rises to 4 from 3.

However, I'm struggling with that algorithm. Which libraries or functions will solve my problem?

Erick Petrucelli
  • 14,386
  • 8
  • 64
  • 84
Quicksilver
  • 75
  • 1
  • 9

1 Answers1

0

It is more like you want to know the delta between two exactly same javascript structures. When I want to find out delta I generally use deep-object-diff. It has multiple difference functions.

From the example from npmjs:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(detailedDiff(lhs, rhs));

/*
{
  added: {
    foo: {
      bar: {
        c: {
          '2': 'z'
        },
        d: 'Hello, world!'
      }
    }
  },
  deleted: {
    foo: {
      bar: {
        a: {
          '1': undefined
        },
        e: undefined
      }
    }
  },
  updated: {
    buzz: 'fizz'
  }
}
*/
Aritra Chakraborty
  • 12,123
  • 3
  • 26
  • 35