Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steveast/c4b07807db8a83046ef81c8b0476bde4 to your computer and use it in GitHub Desktop.
Save steveast/c4b07807db8a83046ef81c8b0476bde4 to your computer and use it in GitHub Desktop.
Собеседование: Отфильтровать объекты от повторяющихся значении.
const array1 = [{
"id": 1,
"name": "apple",
}, {
"id": 2,
"name": "orange"
}];
const array2 = [{
"id": 1,
"name": "apple",
}, {
"id": 4,
"name": "purple"
}];
const unique = array1.concat(array2).filter((cursor, index, source) => (
source.map(record => record['id']).indexOf(cursor['id']) === index
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment