Skip to content

Instantly share code, notes, and snippets.

@llcoollasa
Created November 2, 2019 08:02
Show Gist options
  • Save llcoollasa/a5e33066ebceb18147239cab85019d6f to your computer and use it in GitHub Desktop.
Save llcoollasa/a5e33066ebceb18147239cab85019d6f to your computer and use it in GitHub Desktop.
Object Compare
var accountUsers = [
{_id:1, email:'email1'},
{_id:2, email:'email2'},
{_id:3, email:'email3'},
{_id:4, email:'email4'},
{_id:5, email:'email5'},
];
var calendarUsers = [
{_id:1, email:'email1', status: 'pending'},
{_id:2, email:'email2', status: 'active'},
{_id:3, email:'email3', status: null},
];
// get eligible users for calendar user list
function comparer(arr){
return function(cur) {
return arr.filter(a => a.email === cur.email).length == 0;
}
}
var eligibleList = accountUsers.filter(comparer(calendarUsers));
console.log(eligibleList);
/*
[
{
"_id": 4,
"email": "email4"
},
{
"_id": 5,
"email": "email5"
}
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment