forked from engindemirog/javaScriptStarterKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapFilterReduce.js
More file actions
39 lines (29 loc) · 1.1 KB
/
mapFilterReduce.js
File metadata and controls
39 lines (29 loc) · 1.1 KB
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
let cart = [
{id: 1, productName: "Phone", quantity: 3, unitPrice: 4000},
{id: 2, productName: "Glass", quantity: 2, unitPrice: 30},
{id: 3, productName: "Pen", quantity: 1, unitPrice: 20},
{id: 4, productName: "Charger", quantity: 2, unitPrice: 100},
{id: 5, productName: "Book", quantity: 3, unitPrice: 30},
{id: 6, productName: "Pot", quantity: 5, unitPrice: 150},
]
//cart.map(product => console.log(product.productName));
cart.map(product=>{
console.log(product.productName + ": " + product.unitPrice * product.quantity)
});
let quantityOver2 = cart.filter(product => product.quantity>2);
console.log(quantityOver2);
let total = cart.reduce((acc, product) => acc + product.unitPrice, 0);
console.log(total);
//Add to the cart
//cart.push({id: 7, productName: "Registration", quantity: 1, unitPrice: 20});
//function addToCart(cartA) {
// cartA.push({id: 7, productName: "Registration", quantity: 1, unitPrice: 20});
//}
//AddToCart(cart);
//console.log(cart);
//let number = 10;
//function incrementNr(number) {
// number += 1;
//}
//incrementNr(number);
//console.log(number);