I am comparing two JSON objects and returning only the differences, and it works great. But I need a TRUE or FALSE answer also. Were any new items added to the final array?
Let's assume
result1 = existing vehicles in file
result2 = new vehicle data
Were there any new vehicles added to the file (array) ?
newItemsAdded = ????? // Your code here
const comparer = async function (result1, result2) {
//Find values that are in result1 but not in result2
var uniqueResultOne = result1.filter(function (obj) {
return !result2.some(function (obj2) {
return (obj.title == obj2.title && obj.price==obj2.price && obj.miles==obj2.miles);
});
});
//Find values that are in result2 but not in result1
var uniqueResultTwo = result2.filter(function (obj) {
return !result1.some(function (obj2) {
return (obj.title == obj2.title && obj.price==obj2.price && obj.miles==obj2.miles);
});
});
// Combine the two arrays of unique entries
var result = uniqueResultOne.concat(uniqueResultTwo);
return result;
}