Skip to content

Instantly share code, notes, and snippets.

@MikeDigitize
Created February 14, 2016 20:44
Show Gist options
  • Save MikeDigitize/ff3fc92b022d693a1e91 to your computer and use it in GitHub Desktop.
Save MikeDigitize/ff3fc92b022d693a1e91 to your computer and use it in GitHub Desktop.
var restaraunt = {
orders : [],
order : function(order) {
this.orders.push(order);
},
total : function(orders) {
orders = orders || this.orders;
return orders.reduce(function(total, order) {
return total + order.cost;
}, 0);
},
addVat : function() {
return this.orders.map(function(order) {
order.cost += Math.round(order.cost / 100 * 20);
return order;
});
},
getStarters : function() {
return this.orders.filter(function(order) {
return order.starter;
});
},
getMains : function() {
return this.orders.filter(function(order) {
return order.main;
});
},
isJustMains : function() {
return this.orders.every(function(order) {
return order.main;
});
},
hasStarters : function() {
return this.orders.some(function(order) {
return order.starter;
});
},
getFood : function(food) {
return this.orders.find(function(order) {
return order.starter === food || order.main === food;
});
}
};
restaraunt.order({ main : "Steak and chips", cost : 23.30 });
restaraunt.order({ starter : "Prawn Cocktail", cost : 5.99 });
restaraunt.order({ main : "Roast Dinner", cost : 19.99 });
restaraunt.order({ starter : "Soup of the day", cost : 4.99 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment