Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created June 5, 2020 18:26
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/1964f5d6ca8e57d53b7661347235f8df to your computer and use it in GitHub Desktop.
Save marshallmurphy/1964f5d6ca8e57d53b7661347235f8df to your computer and use it in GitHub Desktop.
function firstComeFirstServe(takeAwayOrders, eatInOrders, servedOrders) {
// if any orders are not accounted for, return false
if ([...takeAwayOrders, ...eatInOrders].length != servedOrders.length) {
return false
}
servedOrders.forEach(order => {
if (takeAwayOrders[0] === order) {
// match!
takeAwayOrders.shift()
} else if (eatInOrders[0] === order) {
// match!
eatInOrders.shift()
} else {
// no match, not first-come first-serve
return false
}
})
// check for remaining extra orders
return [...takeAwayOrders, ...eatInOrders].length == 0 ? true : false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment