Skip to content

Instantly share code, notes, and snippets.

@yosvelquintero
Last active September 12, 2019 08:40
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 yosvelquintero/168cd18e09e00b14082d5542d6b637f9 to your computer and use it in GitHub Desktop.
Save yosvelquintero/168cd18e09e00b14082d5542d6b637f9 to your computer and use it in GitHub Desktop.
const records = [
{ id: 'a', category: 1 },
{ id: 'b', category: 2 },
{ id: 'c', category: 3 },
{ id: 'd', category: 1 },
{ id: 'e', category: 2 },
{ id: 'f', category: 3 },
{ id: 'g', category: 1 },
{ id: 'h', category: 2 }
];
const result = records
.sort((a, b) => a.category - b.category)
.map(r => ({
key: r.category,
value: {
id: r.id,
category: r.category
}
}));
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment