-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncPr-practice.js
More file actions
46 lines (36 loc) · 1.3 KB
/
funcPr-practice.js
File metadata and controls
46 lines (36 loc) · 1.3 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
40
41
42
43
44
45
46
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('총 금액 = ' + totalPrice);
//total Price : 1359000
totalPrice = 0;
cart.forEach((good) => (totalPrice += good.price * good.quantity));
console.log('총 금액 = ' + totalPrice);
//total Price : 1359000
totalPrice = 0;
totalPrice = cart.reduce((a, good) => a + good.price * good.quantity, 0);
console.log('총 금액 = ' + totalPrice);
//total Price : 1359000
/*
const itemTotals = card.map(good => {
item : good.item,
total : good.price * good.quantity;
});*/
/*
제품별 금액: [
{ item: ' ', total: 1200000 }, 노트북
{ item: ' ', total: 70000 }, 마우스
{ item: ' ', total: 89000 } 키보드
]
*/
const names = ['alice', 'bob', 'charlie'];
const uppercasedNames = names.map((n) => n.toUpperCase()); //[ 'ALICE', 'BOB', 'CHARLIE' ]
console.log(`upperCaseNames = ${uppercasedNames}`);
const capitalStartnames = names.map((n) => n[0].toUpperCase() + n.slice(1)); //[ 'Alice', 'Bob', 'Charlie' ]
console.log(`uppercasedNames = ${capitalStartnames}`);