Forked from monkt/gist:0a400e12e4f0e4fc573aa107f5af5caf
Created
April 27, 2017 13:41
-
-
Save abepetrillo/e85169b964022e1f70e6b6abf8a20dad to your computer and use it in GitHub Desktop.
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
input = [ | |
'Writing Fast Tests Against Enterprise Rails 60min, Overdoing it in Python 45min', | |
'Lua for the Masses 30min', | |
'Ruby Errors from Mismatched Gem Versions 45min', | |
'Common Ruby Errors 45min', | |
'Rails for Python Developers lightning', | |
'Communicating Over Distance 60min', | |
'Accounting-Driven Development 45min', | |
'Woah 30min', | |
'Sit Down and Write 30min', | |
'Pair Programming vs Noise 45min', | |
'Rails Magic 60min', | |
'Ruby on Rails: Why We Should Move On 60min', | |
'Clojure Ate Scala (on my project) 45min', | |
'Programming in the Boondocks of Seattle 30min', | |
'Ruby vs. Clojure for Back-End Development 30min', | |
'Ruby on Rails Legacy App Maintenance 60min', | |
'A World Without HackerNews 60min', | |
'User Interface CSS in Rails Apps 30min' | |
] | |
const durations = { | |
'30min' : 30 | |
'45min' : 45 | |
'60min' : 60 | |
'lightning' : 5 | |
} | |
const sessions = { | |
'morning' : 180 | |
'afternoon' : 240 | |
} | |
talkDurationList = input.map (talk) -> { return durations[talk.split(" ").pop()] } # ordererd list of times | |
session = [] | |
currentSession = [] | |
sessionLength = 0 | |
sessionType = 'morning' | |
addTalkToSession = (inputStringWithDuration) -> | |
title = inputStringWithDuration.split(" ") | |
title.pop() | |
title.join(" ") | |
while (talkDurationList.length isnt 0) { | |
talkLength = talkDurationList.pop() | |
if (sessionLength + talkLength <= sessions[sessionType]) { | |
sessionLength += talkLength | |
currentSession.push(addTalkToSession(input[talkDurationList.length])) | |
} | |
else { | |
session.push(currentSession) # create session | |
talkDurationList.push(talkLength) # re-insert talk value | |
sessionType = if sessionType is 'morning' then 'afternoon' else 'morning' # switch the sessionType | |
sessionLength = 0 # reset for new session | |
currentSession = [] | |
} | |
} | |
# output session data | |
sessions.forEach(session, () -> { | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment