Skip to content

Instantly share code, notes, and snippets.

@iancharters
Created June 14, 2020 22:59
Show Gist options
  • Save iancharters/2f4c758f2aeddb20933f8de21e00013f to your computer and use it in GitHub Desktop.
Save iancharters/2f4c758f2aeddb20933f8de21e00013f to your computer and use it in GitHub Desktop.
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