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
28 lines (19 loc) · 822 Bytes
/
mapFilterReduce.js
File metadata and controls
28 lines (19 loc) · 822 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
let cart = [
{id:1, productName:"Telefon", quantity:3, UnitPrice:4000},
{id:1, productName:"Tablet", quantity:3, UnitPrice:5000},
{id:1, productName:"Kulaklık", quantity:3, UnitPrice:700},
{id:1, productName:"Saat", quantity:3, UnitPrice:2000},
{id:1, productName:"Bilgisayar", quantity:3, UnitPrice:7000},
]
console.log("<ul>")
cart.map(product=>{console.log("<li>"+product.productName + ": "+ product.UnitPrice * product.quantity+"</li>")})
console.log("</ul>")
let total = cart.reduce((acc,product)=>acc+ product.UnitPrice * product.quantity,0)
console.log(total)
let quantityOver2 = cart.filter(product=>product.quantity>2)
console.log(quantityOver2)
function addToCart(cart) {
cart.push({id:1, productName:"Monitör", quantity:2, UnitPrice:2500})
}
addToCart(cart)
console.log(cart)