Last active
November 2, 2016 09:44
-
-
Save ccoloma/c603197634b8c6672eed9625b9b9534e to your computer and use it in GitHub Desktop.
Codemotion agenda snippets
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
var slotsByDay = {} | |
// get talks and group them by day | |
agenda.days.forEach( | |
d => { | |
slotsByDay[d.name] = []; | |
d.tracks.forEach( | |
t => t.slots.forEach( | |
s => { | |
if (s.contents && s.contents.description) { | |
slotsByDay[d.name].push({ | |
start: s.start, | |
end: s.end, | |
title: s.contents.title, | |
totalLikes: s.contents.totalLikes | |
}); | |
} | |
} | |
) | |
) | |
} | |
) | |
// sort by time range and then by total likes | |
for (day in slotsByDay) { | |
slotsByDay[day].sort((s1, s2) => { | |
let result = s1.start.localeCompare(s2.start); | |
if (!result) { | |
result = s1.end.localeCompare(s2.end); | |
if (!result) { | |
result = s2.totalLikes - s1.totalLikes; | |
} | |
} | |
return result; | |
}) | |
} | |
console.log(JSON.stringify(slotsByDay, null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment