-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmain.js
70 lines (63 loc) · 1.3 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
'use strict'
const {
listing,
cart,
calculateTotals
} = require('./lib.js')
const regularListings = [
listing('detergent', 10),
listing('hennessey', 100),
listing('carlo rozzi', 20),
listing('coffee', 5),
listing('cookies', 6),
listing('mountain dew', 2)
]
const saleListings = [
listing('detergent', 5),
listing('hennessey', 50),
listing('carlo rozzi', 10),
listing('coffee', 2.5),
listing('cookies', 3),
listing('mountain dew', 1)
]
const carts = [
cart(
'adam',
'carlo rozzi',
'carlo rozzi',
'carlo rozzi',
'carlo rozzi',
'carlo rozzi',
'carlo rozzi'
),
cart(
'david',
'detergent',
'hennessey',
'coffee'
),
cart(
'michael',
'coffee',
'hennessey',
'coffee',
'hennessey',
'coffee',
'hennessey'
),
cart(
'dillon',
'cookies',
'cookies',
'cookies',
'mountain dew',
'mountain dew',
'mountain dew'
)
]
const regularTotals = calculateTotals(regularListings)
const saleTotals = calculateTotals(saleListings)
regularTotals(carts)
.forEach(cart => console.log(`${cart.customer}, your total is ${cart.total}`))
saleTotals(carts)
.forEach(cart => console.log(`${cart.customer}, your total could have been ${cart.total} if you were smart enough to come on a sale day! (you dummy)`))