Answers for "compare two array of object and return unmatched elements"

1

compare two array of object and return unmatched elements

/comparing array 'b' to array 'a' 
//returning unmatched elements from array 'b'
var a=[{icon:"fas fa-biohazard",path:"covid-logs",title:"Covid Logs"},{icon:"fas fa-users",path:"attendance",title:"Attendance Calendar"},{icon:"fas fa-newspaper",path:"news",title:"News"}];
var b=[{path:"all-maintenance-tickets-tracker",title:"Facility Maintenance All",icon:"fas fa-tools"},{path:"billing-provider-pay-billed",title:"Billing (Billed Amount)",icon:"fas fa-money-bill"},{path:"billing-provider-pay-collected",title:"Billing (Collected Amount)",icon:"fas fa-money-bill"},{path:"manager-invoice-approval",title:"Invoice Approval",icon:"fas fa-file-invoice-dollar"},{path:"provider-invoice-submission",title:"Invoice Submission",icon:"fas fa-file-invoice-dollar"},{path:"provider-invoice",title:"Invoice Status",icon:"fas fa-file-invoice-dollar"},{path:"provider-dashboard",title:"Invoice Dashboard",icon:"fas fa-file-invoice-dollar"},{path:"provider-pay-billed",title:"Pay Provider (Billed Amount)",icon:"fas fa-money-check"},{path:"provider-pay-collected",title:"Pay Provider (Collected Amount)",icon:"fas fa-money-check"},{path:"provider-invoices",title:"Provider Invoices",icon:"fas fa-user"},{path:"provider-payscale",title:"Provider Setup",icon:"fas fa-user"},{path:"partner-report",title:"Partner Report",icon:"far fa-handshake"},{path:"employee-list",title:"Hiring",icon:"fas fa-file-signature"},{path:"incident-report-tracker",title:"Incident Report",icon:"fas fa-car-crash"},{path:"attendance-all",title:"Attendance Calendar All",icon:"fas fa-clipboard-user"},{path:"attendance",title:"Attendance Calendar",icon:"fas fa-clipboard-user"},{path:"working-hours",title:"Working Hours",icon:"fas fa-hourglass-half"},{path:"blogs",title:"Blogs",icon:"fab fa-blogger"},{path:"equipment-list",title:"IT Equipments",icon:"far fa-computer-classic"},{path:"all-tickets-tracker",title:"IT Tickets All",icon:"far fa-sitemap"},{path:"follow-up-calls",title:"Follow Up Calls (FD)",icon:"fas fa-phone-volume"},{path:"follow-up",title:"Follow Up Tracker",icon:"fad fa-analytics"},{path:"patients",title:"Patient Tracker",icon:"fal fa-analytics"},{path:"hrt-questionnaire-list",title:"HRT Questionnaire",icon:"fas fa-question-circle"},{path:"ams-questionnaire-list",title:"AMS Questionnaire",icon:"fas fa-question-square"},{path:"puf-tracker",title:"PUF Tracker",icon:"fas fa-analytics"},{path:"contacts",title:"Contacts",icon:"fas fa-address-book"},{path:"meeting-groups",title:"Meeting Groups",icon:"fas fa-chalkboard-teacher"},{path:"covid-logs",title:"Covid Logs",icon:"fas fa-biohazard"},{path:"maintenance-tickets-tracker",title:"Facility Maintenance",icon:"fas fa-tools"},{path:"portal-health",title:"Daily Processes Status",icon:"fas fa-download"},{path:"tickets-tracker",title:"IT Tickets",icon:"far fa-sitemap"},{path:"admin/users",title:"Users",icon:"fas fa-users"},{icon:"fas fa-newspaper",path:"news",title:"News"}];

var result = b.filter(function(obj) {
    return !a.some(function(obj2) {
        return obj.path == obj2.path;
    });
});

//typescript 
var result = b.filter((obj) => {
    return !a.some((obj2) => {
        return obj.path == obj2.path;
    });
});
Posted by: Guest on September-23-2021
-1

comparing two array of objects in javascript returning differences

a = [{ value:"4a55eff3-1e0d-4a81-9105-3ddd7521d642", display:"Jamsheer"}, { value:"644838b3-604d-4899-8b78-09e4799f586f", display:"Muhammed"}, { value:"b6ee537a-375c-45bd-b9d4-4dd84a75041d", display:"Ravi"}, { value:"e97339e1-939d-47ab-974c-1b68c9cfb536", display:"Ajmal"},  { value:"a63a6f77-c637-454e-abf2-dfb9b543af6c", display:"Ryan"}]
b = [{ value:"4a55eff3-1e0d-4a81-9105-3ddd7521d642", display:"Jamsheer", $$hashKey:"008"}, { value:"644838b3-604d-4899-8b78-09e4799f586f", display:"Muhammed", $$hashKey:"009"}, { value:"b6ee537a-375c-45bd-b9d4-4dd84a75041d", display:"Ravi", $$hashKey:"00A"}, { value:"e97339e1-939d-47ab-974c-1b68c9cfb536", display:"Ajmal", $$hashKey:"00B"}]

function comparer(otherArray){
  return function(current){
    return otherArray.filter(function(other){
      return other.value == current.value && other.display == current.display
    }).length == 0;
  }
}

var onlyInA = a.filter(comparer(b));
var onlyInB = b.filter(comparer(a));

result = onlyInA.concat(onlyInB);

console.log(result);
Posted by: Guest on July-08-2020

Code answers related to "compare two array of object and return unmatched elements"

Code answers related to "Javascript"

Browse Popular Code Answers by Language