-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncPr-practice.html
More file actions
34 lines (31 loc) · 957 Bytes
/
funcPr-practice.html
File metadata and controls
34 lines (31 loc) · 957 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
const cart = [
{item:"노트북", price:1200000,quantity:1},
{item:"마우스", price:35000,quantity:2},
{item:"키보드", price:89000,quantity:1}
];
let totalPrice=0;
for(let i=0;i<cart.length;i++){
totalPrice+=cart[i].price*cart[i].quantity
}
console.log(`Total Price: ${totalPrice}`);
totalPrice=0;
cart.forEach(
a=>totalPrice+=a.price*a.quantity
);
console.log(`Total Price: ${totalPrice}`);
totalPrice=0;
totalPrice=cart.reduce(
(a,b)=>(a+b.price*b.quantity),0
);
console.log(`Total Price: ${totalPrice}`);
totalPrice=0;
const itemTotals=cart.map(
a=>({item:a.item,
total:a.price*a.quantity})
);
console.log('제품별 금액: ',itemTotals);
const names=['alice','bob','charlie'];
const uppercasedNames=names.map(n=>n.toUpperCase());
console.log(`upperCaseNames = ${uppercasedNames}`);
const capitalStartNames=names.map(n=>n[0].toUpperCase()+n.slice(1));
console.log(`capitalStartNames = ${capitalStartNames}`);