Created
June 23, 2017 16:56
-
-
Save amboy00/5cc69062820ca5fdfe8c66df82a1cee6 to your computer and use it in GitHub Desktop.
compare to arrays of objects, return only the difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Finding the difference between to arrays of objects | |
// As told through the magic of... | |
// _____ _ _____ _ _ | |
// / ____| (_) / ____(_) | | | |
// | (___ _ __ _ ___ ___ | | __ _ _ __| |___ | |
// \___ \| '_ \| |/ __/ _ \ | | |_ | | '__| / __| | |
// ____) | |_) | | (_| __/ | |__| | | | | \__ \ | |
// |_____/| .__/|_|\___\___| \_____|_|_| |_|___/ | |
// | | | |
// |_| | |
const beforeSpiceWorld = [ | |
{name: 'Ginger', isMember:true}, | |
{name: 'Baby', isMember:true}, | |
{name: 'Posh', isMember:true}, | |
{name: 'Scary', isMember:true}, | |
{name: 'Sporty', isMember:true} | |
] | |
const AfterSpiceWorld = [ | |
{name: 'Ginger', isMember:false}, | |
{name: 'Baby', isMember:true}, | |
{name: 'Posh', isMember:true}, | |
{name: 'Scary', isMember:true}, | |
{name: 'Sporty', isMember:true} | |
] | |
// 2 Become 1 | |
const whoRuinedEverything = AfterSpiceWorld.filter(after => | |
beforeSpiceWorld.filter(before => | |
before.name === after.name && before.isMember === after.isMember | |
).length === 0 | |
); | |
console.log(whoRuinedEverything); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment