Skip to content

Instantly share code, notes, and snippets.

@Dartv
Created October 9, 2015 06:02
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 Dartv/8ab6b176cb6ac52a5a34 to your computer and use it in GitHub Desktop.
Save Dartv/8ab6b176cb6ac52a5a34 to your computer and use it in GitHub Desktop.
Unique objects from array with max property
arr = [
{ id: 324, difficulty: 3 },
{ id: 324, difficulty: 2 },
{ id: 324, difficulty: 5 },
{ id: 500, difficulty: 3 },
{ id: 500, difficulty: 3.5 },
{ id: 500, difficulty: 7 }
];
let map = _.groupBy(arr, (el) => el.id)
let array = [];
_.each(map, (element) => {
let max = _.max(element, (el) => el.difficulty);
console.log(max);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment