-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixed-juices.js
59 lines (56 loc) · 1.25 KB
/
mixed-juices.js
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
/**
* Determines how long it takes to prepare a certain juice.
*
* @param {string} name
* @returns {number} time in minutes
*/
export function timeToMixJuice(name) {
switch (name) {
case 'Pure Strawberry Joy':
return 0.5;
case 'Energizer':
return 1.5;
case 'Green Garden':
return 1.5;
case 'Tropical Island':
return 3;
case 'All or Nothing':
return 5;
default:
return 2.5;
}
}
/**
* Calculates the number of limes that need to be cut
* to reach a certain supply.
*
* @param {number} wedgesNeeded
* @param {string[]} limes
* @returns {number} number of limes cut
*/
const LIME_SIZES_TO_WEDGES = {
small: 6,
medium: 8,
large: 10
}
export function limesToCut(wedgesNeeded, limes) {
let limes_cut=0
while (wedgesNeeded > 0 & limes.length > 0) {
limes_cut ++;
wedgesNeeded -= LIME_SIZES_TO_WEDGES[limes.shift()];
}
return limes_cut;
}
/**
* Determines which juices still need to be prepared after the end of the shift.
*
* @param {number} timeLeft
* @param {string[]} orders
* @returns {string[]} remaining orders after the time is up
*/
export function remainingOrders(timeLeft, orders) {
while (timeLeft > 0 && orders.length > 0){
timeLeft -= timeToMixJuice(orders.shift());
}
return orders;
}