Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution() {
- const ingredients = {
- protein: 0,
- carbohydrate: 0,
- fat: 0,
- flavour: 0,
- };
- const recipe = {
- apple: { carbohydrate: 1, flavour: 2 },
- lemonade: { carbohydrate: 10, flavour: 20 },
- burger: { carbohydrate: 5, fat: 7, flavour: 3 },
- eggs: { protein: 5, fat: 1, flavour: 1 },
- turkey: { protein: 10, carbohydrate: 10, fat: 10, flavour: 10 },
- };
- const commands = {
- restock: (elem, quantity) => {
- ingredients[elem] += Number(quantity);
- return "Success";
- },
- prepare: (product, quantity) => {
- for (el in recipe[product]) {
- if (recipe[product][el] * Number(quantity) > ingredients[el]) {
- return `Error: not enough ${el} in stock`;
- }
- }
- for (el in recipe[product]) {
- ingredients[el] -= recipe[product][el] * Number(quantity);
- }
- return "Success";
- },
- report: () => {
- return `protein=${ingredients.protein} carbohydrate=${ingredients.carbohydrate} fat=${ingredients.fat} flavour=${ingredients.flavour}`;
- },
- };
- function manager(text) {
- let [com, ...args] = text.split(" ");
- return commands[com](...args);
- }
- return manager;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement