Structural Kitchen
A Learning TypeScript > Functions 🍲 entree project.
Greetings. I am Chef Syntax, creator of the famed Structural Kitchen restaurant. We humbly request your aid in digitizing our kitchen management software.
A createKitchen function must be created that returns an object containing functions.
It must receive an initial budget and two functions as parameters.
It should create some state for the kitchen internally.
If you are willing and able to be of service, see below for our exact specification.
Setup
If you haven't yet, set up the github.com/LearningTypeScript/projects repository locally.
shellgit clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
shellgit clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
Open your editor in this project's directory:
shellcode projects/functions/structural-kitchen
shellcode projects/functions/structural-kitchen
In one terminal, run the TypeScript compiler via the tsc script.
For example, to start the TypeScript compiler in watch mode:
shellnpm run tsc -- --watch
shellnpm run tsc -- --watch
In another terminal, run Jest via the test script.
For example, to start tests in watch mode:
shellnpm run test -- --watch
shellnpm run test -- --watch
Specification
You must export a createKitchen function.
Inside the kitchen is the following state:
dirt: How much dirt is in the kitchen, initially0stock: How much of each of the following are in the kitchen, each initially0:breadsfruitssaucesvegetables
It must take in three parameters:
budget: A starting budget number the kitchen may use for its costscleaner: A function with...- Parameters:
dirt: How much dirt is in the kitchentime(optional): How much time to spend cleaning
- Return: A new number for how much dirt should be left in the kitchen
- Parameters:
supplier: A function with...- Parameters:
expense: How much money from the budget will be spent on purchasing
- Return: An object with for each stock ingredient name keyed to how much to increase that ingredient by
- Parameters:
It must return an object with the following properties:
announce: A function that returns a string in the format (replacing each#with the corresponding number):plaintextI have # much dirt, # budget, # bread(s), # fruit(s), # sauce(s), and # vegetable(s).plaintextI have # much dirt, # budget, # bread(s), # fruit(s), # sauce(s), and # vegetable(s).clean: A function that sets thedirtstate to the result of callingcleaneron the existingdirtamount andtimeparameter.- Parameters:
time(optional): How much time to spend cleaning
- Parameters:
purchase: A function that takes in anexpenseamount and, if there is enough budget for that expense, callssupplierwith it and increases stock by the results.- Parameters:
expense: How much money to spend on cleaning
- Return: A boolean indicating whether there was enough budget
- Parameters:
prepare: A function that attempts to make a recipe and increasedirtstate by1, but only if thedirtstate is below100.- Parameters:
recipe: A function that takes in an object describing the ingredients, and returns either:- Failure result: an object containing
succeeded: false - Success result: an object containing
succeeded: trueand anewStockproperty indicating the new ingredients state
- Failure result: an object containing
- Return: A boolean indicating whether dirt was previously below
100and the recipe was successfully created
- Parameters:
Please use an explicit return type annotation on the createKitchen function.
Call that aliased object type Kitchen.
Notes
Note: your terminal should be in the
structural-kitchendirectory, not the root repository's directory.
- Don't use
any.