I'm running a test each day that goes to a page and reads some data. Oldest info are put to the end of the array, newest at the beginning. There will be situations when some entries are removed from the page and some are added. But still the order will be the same - older at the end, newer at the beginning.
After each run, when data is taken I need to compare it with the entry in db. The output should be like: [entries_existing_only_in_new_run, entries_from_old_run_but_existing_also_in_new_run]. Maybe example will be better :D
Have two arrays:
const new = [
{
role: 'dev',
some: 'new'
},
{
role: 'dev',
some: 'new'
},
{
role: 'dev',
some: 'new'
},
{
role: 'qa',
some: 'new'
},
{
role: 'sm',
some: 'new'
},
]
const old = [
{
role: 'dev',
some: 'old'
},
{
role: 'qa',
some: 'old'
},
{
role: 'sm',
some: 'old'
},
{
role: 'tl',
some: 'old'
},
]
The point here is to compare role from those two arrays, take beginning of the new one (that is missing in the old one) and the rest from the old one. As tl role is missing in the new entry it should not be added. So the output should be
const modified = [
{
role: 'dev',
some: 'new'
},
{
role: 'dev',
some: 'new'
},
{
role: 'dev',
some: 'old'
},
{
role: 'qa',
some: 'old'
},
{
role: 'sm',
some: 'old'
},
]
How to do it? :)