Last active
September 12, 2019 08:40
-
-
Save yosvelquintero/168cd18e09e00b14082d5542d6b637f9 to your computer and use it in GitHub Desktop.
This file contains 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
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