-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlasagna-master.js
More file actions
79 lines (71 loc) · 1.95 KB
/
Copy pathlasagna-master.js
File metadata and controls
79 lines (71 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// <reference path="./global.d.ts" />
import { throws } from "assert";
// @ts-check
/**
* Implement the functions needed to solve the exercise here.
* Do not forget to export them so they are available for the
* tests. Here an example of the syntax as reminder:
*
* export function yourFunction(...) {
* ...
* }
*/
/**
* Check the cooking status by remaining time.
*
* @param {number} remainingTime
* @returns {string} the cooking status
*/
export function cookingStatus(remainingTime) {
if (remainingTime === 0) return "Lasagna is done.";
if (!remainingTime) return "You forgot to set the timer.";
return "Not done, please wait.";
}
/**
* Estimate the preparation time by given array of layers and average preparation time
*
* @param {String[]} layers
* @param {number} meanPrepTime
* @returns {number} the estimated preparation time
*/
export function preparationTime(layers, meanPrepTime) {
return layers.length * (meanPrepTime || 2);
}
/**
* Calculate the quantities of noodles and sauce required to cook the lasagna
*
* @param {String[]} layers
* @returns {Recipe} the amount of noodles and sauce required
*/
export function quantities(layers) {
const numberOfNoodles = layers.filter(
ingredient => ingredient.toLowerCase() === "noodles"
).length;
const numberOfSauce = layers.filter(
ingredient => ingredient.toLowerCase() === "sauce"
).length;
return { noodles: numberOfNoodles * 50, sauce: numberOfSauce * 0.2 };
}
/**
* Add secret ingredient of friend into my list
*
* @param {String[]} friendsList
* @param {String[]} myList
*/
export function addSecretIngredient(friendsList, myList) {
myList.push(friendsList[friendsList.length - 1]);
}
/**
*
* @param {Recipe} recipe
* @param {number} factor
* @returns
*/
export function scaleRecipe(recipe, factor) {
factor = factor * 0.5 || 1;
const scaledRecipe = { ...recipe };
for (const ingredient in scaledRecipe) {
scaledRecipe[ingredient] *= factor;
}
return scaledRecipe;
}