Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created June 5, 2020 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshallmurphy/09e6feaf12320647a4eca684dfef5570 to your computer and use it in GitHub Desktop.
Save marshallmurphy/09e6feaf12320647a4eca684dfef5570 to your computer and use it in GitHub Desktop.
def first_come_first_served?(take_away_orders, eat_in_orders, served_orders)
served_orders.each do |order|
if take_away_orders[0] === order
# match!
take_away_orders.shift()
elsif eat_in_orders[0] === order
# match!
eat_in_orders.shift()
else
# no match, not first-come first-serve
return false
end
end
# check for remaining extra orders
return take_away_orders.concat(eat_in_orders).length == 0 ? true : false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment