Skip to content

Commit 2906532

Browse files
committed
sprint 1 destructuring completed
1 parent 1c7f86d commit 2906532

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

Sprint-1/destructuring/exercise-2/exercise.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ function getGryffindorHousePeople(list) {
7575
let result = [];
7676
list.forEach((person) => {
7777
const { firstName, lastName, house } = person;
78-
if (house === "Gryffindor") result.push(`${firstName} ${lastName}`);
78+
if (house === "Gryffindor")
79+
result.push(`
80+
${firstName} ${lastName}`);
7981
});
8082
return result;
8183
}
@@ -84,11 +86,13 @@ function findTeachersHavingPets(list) {
8486
let result = [];
8587
list.forEach((person) => {
8688
const { firstName, lastName, pet } = person;
87-
if (pet !== null) result.push(`${firstName} ${lastName}`);
89+
if (pet !== null)
90+
result.push(`
91+
${firstName} ${lastName}`);
8892
});
8993
return result;
9094
}
9195

92-
console.log(getGryffindorHousePeople(hogwarts));
96+
console.log(...getGryffindorHousePeople(hogwarts));
9397

94-
console.log(findTeachersHavingPets(hogwarts));
98+
console.log(...findTeachersHavingPets(hogwarts));

Sprint-1/destructuring/exercise-3/exercise.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,23 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
9+
10+
function printReceipt(order) {
11+
let receipt = [];
12+
let total = 0;
13+
receipt.push(`
14+
QTY ITEM TOTAL`);
15+
order.forEach((item) => {
16+
const { itemName, quantity, unitPricePence } = item;
17+
const itemTotal = (quantity * unitPricePence) / 100;
18+
total += itemTotal;
19+
receipt.push(`
20+
${quantity} ${itemName.padEnd(20)} ${itemTotal.toFixed(2)}`);
21+
});
22+
receipt.push(`
23+
24+
Total: ${total.toFixed(2)}`);
25+
console.log(...receipt);
26+
}
27+
28+
printReceipt(order);

0 commit comments

Comments
 (0)