-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-and-tests-plain-js.js
More file actions
39 lines (34 loc) · 961 Bytes
/
Copy pathcode-and-tests-plain-js.js
File metadata and controls
39 lines (34 loc) · 961 Bytes
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
// function orderTotal(order) {
// return order.items.reduce((prev, current) => current.price * (current.quantity || 1) + prev, 0)
// }
const orderTotal = order => order.items.reduce((prev, current) => current.price * (current.quantity || 1) + prev, 0)
if ( orderTotal({
items: [
{ name: "Food", price: 8, quantity: 2}
]
}) !== 16 ) {
throw new Error("Check fail - Example - quantity")
}
if ( orderTotal({
items: [
{ name: "Lead", price: 3 }
]
}) !== 3 ) {
throw new Error("Check fail - Example - No quantity")
}
if ( orderTotal({
items: [
{ name: "Food", price: 8, quantity: 1},
{ name: "Cage", price: 500, quantity: 1}
]
}) !== 508 ) {
throw new Error("Check fail - Example 1")
}
if ( orderTotal({
items: [
{ name: "Collar", price: 20, quantity: 1},
{ name: "Chew toy", price: 40, quantity: 1}
]
}) !== 60 ) {
throw new Error("Check fail - Example 2")
}