Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. input = [
  2. 'Writing Fast Tests Against Enterprise Rails 60min, Overdoing it in Python 45min',
  3. 'Lua for the Masses 30min',
  4. 'Ruby Errors from Mismatched Gem Versions 45min',
  5. 'Common Ruby Errors 45min',
  6. 'Rails for Python Developers lightning',
  7. 'Communicating Over Distance 60min',
  8. 'Accounting-Driven Development 45min',
  9. 'Woah 30min',
  10. 'Sit Down and Write 30min',
  11. 'Pair Programming vs Noise 45min',
  12. 'Rails Magic 60min',
  13. 'Ruby on Rails: Why We Should Move On 60min',
  14. 'Clojure Ate Scala (on my project) 45min',
  15. 'Programming in the Boondocks of Seattle 30min',
  16. 'Ruby vs. Clojure for Back-End Development 30min',
  17. 'Ruby on Rails Legacy App Maintenance 60min',
  18. 'A World Without HackerNews 60min',
  19. 'User Interface CSS in Rails Apps 30min'
  20. ]
  21.  
  22. const durations = {
  23. '30min' : 30
  24. '45min' : 45
  25. '60min' : 60
  26. 'lightning' : 5
  27. }
  28. const sessions = {
  29. 'morning' : 180
  30. 'afternoon' : 240
  31. }
  32.  
  33. talkDurationList = input.map (talk) -> { return durations[talk.split(" ").pop()] } # ordererd list of times
  34.  
  35. session = []
  36. currentSession = []
  37. sessionLength = 0
  38. sessionType = 'morning'
  39.  
  40. addTalkToSession = (inputStringWithDuration) ->
  41. title = inputStringWithDuration.split(" ")
  42. title.pop()
  43. title.join(" ")
  44.  
  45. while (talkDurationList.length isnt 0) {
  46. talkLength = talkDurationList.pop()
  47. if (sessionLength + talkLength <= sessions[sessionType]) {
  48. sessionLength += talkLength
  49. currentSession.push(addTalkToSession(input[talkDurationList.length]))
  50. }
  51. else {
  52. session.push(currentSession) # create session
  53. talkDurationList.push(talkLength) # re-insert talk value
  54. sessionType = if sessionType is 'morning' then 'afternoon' else 'morning' # switch the sessionType
  55. sessionLength = 0 # reset for new session
  56. currentSession = []
  57. }
  58. }
  59.  
  60. # output session data
  61. sessions.forEach(session, () -> {
  62.  
  63. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement