This file contains 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
destinations = [ | |
{ priority: 1, destination_id: "A", trucks: 2, still_needed: 2 }, | |
{ priority: 2, destination_id: "B", trucks: 2, still_needed: 2 }, | |
{ priority: 3, destination_id: "C", trucks: 1, still_needed: 1 } | |
] | |
def next_destination | |
# reset if everyone has been fully supplied | |
if destinations.select{|dest| dest[:still_needed] == 0}.count == destinations.count | |
destinations.map{|dest| dest[:still_needed] = dest[:trucks]} |