Skip to content

Instantly share code, notes, and snippets.

@aromanyuk
Last active February 26, 2016 01:44
Show Gist options
  • Save aromanyuk/ceb9ab27bf1c828f0408 to your computer and use it in GitHub Desktop.
Save aromanyuk/ceb9ab27bf1c828f0408 to your computer and use it in GitHub Desktop.
let foo, bar, firstMethod, secondMethod;
foo = [];
foo.push({ value: 'ua', long: 'Ukraine' });
foo.push({ value: 'en', long: 'USA' });
foo.push({ value: 'uk', long: 'United Kingom' });
foo.push({ value: 'ca', long: 'Canada' });
foo.push({ value: 'de', long: 'Germany' });
bar = [];
bar.push({ value: 'ca', long: 'Canada' });
bar.push({ value: 'en', long: 'USA' });
firstMethod = [];
foo.forEach(fooItem => {
bar.some(barItem => { return fooItem.value === barItem.value; })
|| firstMethod.push(fooItem);
});
secondMethod = foo.filter(fooItem => {
// return bar.map(barItem => barItem.value).indexOf(fooItem.value) === -1; //if [].includes is not defined
return bar.map(barItem => barItem.value).includes(fooItem.value);
});
console.log('First Method: ', firstMethod);
console.log('Second Method: ', secondMethod);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment