Skip to content

Instantly share code, notes, and snippets.

@royhowie
Created July 26, 2015 03:07
Show Gist options
  • Save royhowie/6ed0127acc3b05b29aca to your computer and use it in GitHub Desktop.
Save royhowie/6ed0127acc3b05b29aca to your computer and use it in GitHub Desktop.
which one?
function addSession (subject, calEvent) {
let index = getIndex(this.sessions, (session) => session.subject === subject.id)
if (index === -1) {
this.sessions.push({
subject: subject.id,
hours: 1,
events: calEvent ? [ calEvent ] : []
})
} else {
this.sessions[index].hours += 1
if (calEvent) {
let calEventIndex = getIndex(this.sessions[index], (ev) => ev === calEvent.id)
if (calEventIndex === -1) {
this.sessions[index].events.push(calEvent)
} else {
throw new Error('That calendar event has already been added to the cart.')
}
}
}
return this
}
function addSession (subject, calEvent) {
let index = getIndex(this.sessions, (session) => session.subject === subject.id)
if (-1 === index) {
this.sessions.push({ subject: subject.id, hours: 0, events: [] })
index = 0
}
this.sessions[index].hours += 1
if (calEvent) {
let calEventIndex = getIndex(this.sessions[index], (ev) => ev === calEvent.id)
if (calEventIndex === -1) {
this.sessions[index].events.push(calEvent)
} else {
throw new Error('That calendar event has already been added to the cart.')
}
}
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment