Created
June 14, 2020 22:59
-
-
Save iancharters/2f4c758f2aeddb20933f8de21e00013f 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
function createObjectFromTypes<T>({types, data}: {types: string[]; data: T[]}) { | |
const sortedData = types.reduce((acc, type) => { | |
const typeData = data.reduce((acc, item) => { | |
if (item.sys.contentType.sys.id === type) { | |
return [...acc, item]; | |
} | |
return acc; | |
}, []); | |
acc[type] = x; | |
return acc; | |
}, {}); | |
return sortedData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment