Created
November 25, 2020 17:43
-
-
Save AitorAlejandro/174b0b2743f1da2d3b7cd0de2c5fe0a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 indexBy = (key, xs) => xs.reduce(acc, el) => ({ | |
...acc, | |
[el[key]]: el, | |
}); | |
/* | |
example: | |
// const users = [ | |
{id: 'id1', name: 'Aritz'}, | |
{id: 'id2', name: 'Asier'}, | |
] | |
const indexedUsers = indexBy('id', users); | |
{ | |
id1: {id: 'id1', name: 'Aritz'} | |
id2: {id: 'id2', name: 'Asier'} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment