-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathacme-prework.js
96 lines (89 loc) · 1.64 KB
/
acme-prework.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//instructions
//write the 4 functions below
//no third party libraries
//try not to use any forEach
//each function should be short and some functions can depend on other functions (hint no function should be more than 10 lines)
//list of products
var products = [
{
id: 1,
price: 5,
name: 'foo'
},
{
id: 2,
price: 3,
name: 'bar'
},
{
id: 3,
price: 9,
name: 'bazz'
}
];
//list of line items
var lineItems = [
{
productId: 1,
quantity: 1
},
{
productId: 1,
quantity: 1
},
{
productId: 2,
quantity: 1
},
{
productId: 3,
quantity: 1
},
];
//returns an object
//keys are the ids of products
//the values are the products themselves
function generateProductsMap(products){
//TODO
}
//returns an object
//keys are the ids of products
//value is the total revenue for that product
function salesByProduct(products, lineItems){
//TODO
}
//return the total revenue for all products
function totalSales(products, lineItems){
//TODO
}
//return the product responsible for the most revenue
function topSellerByRevenue(products, lineItems){
//TODO
}
console.log(`generates product map - should be
{
1:{
id: 1,
name: "foo",
price: 5
},
2:{
id: 2,
name: "bar",
price: 3
},
3:{
id: 3,
name: "bazz",
price: 9
}
}
`, generateProductsMap(products));
console.log(`sales by product - should be
{
1: 10,
2: 3,
3: 9
}`, salesByProduct( products, lineItems));
console.log('total sales - should be 22', totalSales( products, lineItems));
console.log('top seller by revenue', topSellerByRevenue(products, lineItems ));