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
}