Last active
February 26, 2016 01:44
-
-
Save aromanyuk/ceb9ab27bf1c828f0408 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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