Created
February 14, 2016 20:44
-
-
Save MikeDigitize/ff3fc92b022d693a1e91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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