Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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, () -> {
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement