Skip to content

Instantly share code, notes, and snippets.

@AshMartian
Created April 5, 2014 21:15
Show Gist options
  • Save AshMartian/9998193 to your computer and use it in GitHub Desktop.
Save AshMartian/9998193 to your computer and use it in GitHub Desktop.
Separating sessions into an array of objects containing an array and date string.
console.log(this.get('model.content'));
//loop through the sessions
this.get('model.content').forEach(function(session){
if (session.get('isActive')) {
var sessionDate = moment(session.get('sessionStart'));
var formatDay = sessionDate.format("dddd, MMMM Do YYYY");
var shouldAddNewDay = true;
sessions.forEach(function(sessionDay){
if (formatDay === sessionDay.formatDay) {
sessionDay.sessions.push(session);
shouldAddNewDay = false;
return false;
}
});
if (shouldAddNewDay === true) {
var day = {
formatDay: formatDay,
sessions:[session]
};
sessions.push(day);
}
}
});
console.log(sessions);
this.set('sessionsToDisplay', sessions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment