Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const emptyEngagements = {
- total_reactions: 0,
- reactions: {
- likes: 0,
- },
- comments: 0,
- reshares: 0,
- };
- export const getSortedSamples = (samples = { web= [] , twitter= [] }: any) => {
- const decoreateSample = source => sample => ({
- ...sample,
- sourceForDisplay: source,
- engagements: sample.engagements || { ...emptyEngagements },
- })
- const sortByPostedTime = (sampleA, sampleB) => dayjs(sampleA.posted_time).isBefore(sampleB.posted_time) ? -1 : 1
- return [
- ...samples.twitter.map(decoreateSample(SOURCES_FOR_DISPLAY.TWITTER)),
- ...samples.web.map(decoreateSample(SOURCES_FOR_DISPLAY.WEB)),
- ].sort(sortByPostedTime)
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement