-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6-11-priceOrder.js
48 lines (39 loc) Β· 1.12 KB
/
6-11-priceOrder.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
/**
* p216 μμ
*/
function priceOrder(product, quantity, shippingMethod) {
const priceData = calculatePricingData(product, quantity);
return applyShipping(priceData, shippingMethod);
}
function calculatePricingData(product, quantity) {
const basePrice = product.basePrice * quantity;
const discount =
Math.max(quantity - product.discountThreshold, 0) *
product.basePrice *
product.discountRate;
return { basePrice, quantity, discount };
}
function applyShipping(priceData, shippingMethod) {
const shippingPerCase =
priceData.basePrice > shippingMethod.discountThreshold
? shippingMethod.discountedFee
: shippingMethod.feePerCase;
const shippingCost = priceData.quantity * shippingPerCase;
return priceData.basePrice - priceData.discount + shippingCost;
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const product = {
basePrice: 10000,
discountThreshold: 5,
discountRate: 0.1,
};
const quantity = 10;
const shippingMethod = {
feePerCase: 3000,
discountThreshold: 50000,
discountedFee: 0,
};
const price = priceOrder(product, quantity, shippingMethod);
console.log(price);