Created
August 31, 2018 19:13
-
-
Save thiagovilla/cf497901c8df99374805ccc9eb197101 to your computer and use it in GitHub Desktop.
Function that normalizes a collection (an array) of objects into an 'allIds' ordered array and a 'byId' object whose keys are each individual object id
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 normalize = items => ({ | |
byId: items.reduce((_items, item) => ({ | |
..._items, | |
[item.id]: item | |
}), {}), | |
allIds: items.map(item => item.id) | |
}) | |
export default normalize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment