Last active
May 22, 2018 01:30
-
-
Save mandiwise/bda1b921e12817373560d626970d630d to your computer and use it in GitHub Desktop.
Function to help format data fetched from the R10 Graphcool API for a React Native SectionList.
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
// Helper to format GraphQL data into section list data | |
export const formatSessionData = sessions => { | |
return sessions | |
.reduce((acc, curr) => { | |
const timeExists = acc.find(section => section.title === curr.startTime); | |
timeExists | |
? timeExists.data.push(curr) | |
: acc.push({ title: curr.startTime, data: [curr] }); | |
return acc; | |
}, []) | |
.sort((a, b) => a.title - b.title); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment