-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandy_sale.js
58 lines (52 loc) · 1.11 KB
/
candy_sale.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
/*
It's the day after Halloween 🎃 and all the candy is on sale!
To buy up all the candy, use map() and filter() to put all the
candy into a `shoppingCart` array.
The new array should contain only the item and the price, like
this:
Expected output:
[
{item: "🍭", price: 2.99},
{item: "🍫", price: 1.99},
{item: "🍬", price: 0.89}
]
*/
let shopitems = [
{
item: "🍭",
price: 2.99,
type: "sweet",
},
{
item: "🍫",
price: 1.99,
type: "sweet",
},
{
item: "🥫",
price: 1.99,
type: "savory",
},
{
item: "🍬",
price: .89,
type: "sweet",
},
{
item: "🥦",
price: 3.99,
type: "savory",
},
{
item: "🍖",
price: 3.99,
type: "savory",
},
]
function getSaleItems(data) {
const onlyCandies = data.filter(({ type }) => type === "sweet");
return onlyCandies.map(({ item, price }) => {
return { item, price }
})
};
console.log(getSaleItems(shopitems));