Skip to content

Instantly share code, notes, and snippets.

@stepanmas
Last active October 23, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepanmas/c4b07807db8a83046ef81c8b0476bde4 to your computer and use it in GitHub Desktop.
Save stepanmas/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((obj, pos, arr) => arr.map(mapObj => mapObj['id']).indexOf(obj['id']) === pos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment