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.
shell
git clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
shell
git clone https://github.com/LearningTypeScript/projects learning-typescript-projectscd learning-typescript-projectsnpm i
Open your editor in this project's directory:
shell
code projects/functions/structural-kitchen
shell
code 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:
shell
npm run tsc -- --watch
shell
npm run tsc -- --watch
In another terminal, run Jest via the test
script.
For example, to start tests in watch mode:
shell
npm run test -- --watch
shell
npm 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, initially0
stock
: How much of each of the following are in the kitchen, each initially0
:breads
fruits
sauces
vegetables
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 thedirt
state to the result of callingcleaner
on the existingdirt
amount andtime
parameter.- Parameters:
time
(optional): How much time to spend cleaning
- Parameters:
purchase
: A function that takes in anexpense
amount and, if there is enough budget for that expense, callssupplier
with 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 increasedirt
state by1
, but only if thedirt
state 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: true
and anewStock
property indicating the new ingredients state
- Failure result: an object containing
- Return: A boolean indicating whether dirt was previously below
100
and 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-kitchen
directory, not the root repository's directory.
- Don't use
any
.