Skip to content

Commit 951c77b

Browse files
committed
updated exercise-2 and exercise-3
1 parent 141a115 commit 951c77b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ let hogwarts = [
7373

7474

7575
function gryffindorHouse(hogwarts) {
76-
return hogwarts.filter(({house}) => house === 'Gryffindor').map(({firstName, lastName}) => `${firstName} ${lastName}`).join("\n")
76+
return hogwarts
77+
.filter(({house}) => house === 'Gryffindor')
78+
.map(({firstName, lastName}) => `${firstName} ${lastName}`)
79+
.join("\n")
7780
}
7881

7982
function teachersWithPets(hogwarts) {
80-
return hogwarts.reduce((nameList, {firstName, lastName, pet, occupation}) => {
81-
if (occupation === "Teacher" && pet !== null) {
82-
nameList.push(`${firstName} ${lastName}`)
83-
}
84-
return nameList;
85-
}, []).join("\n")
83+
return hogwarts
84+
.filter(({occupation, pet}) => occupation === "Teacher" && pet !== null)
85+
.map(({firstName, lastName}) => `${firstName} ${lastName}`)
86+
.join("\n")
8687
}
8788

8889
console.log(gryffindorHouse(hogwarts));
90+
console.log(teachersWithPets(hogwarts))

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ function receiptAndCosts(order) {
1414
let receipt = []
1515

1616
function orderLineFormatting(...args) {
17+
if (args.length !== 3) {
18+
throw new Error("expecting 3 arguments in order of quantity, itemName, and subTotal")
19+
}
1720
const orderLineSpacing = [8, 20, 5]
1821
let formattedOrderLine = ''
1922
for (let index = 0; index < args.length; index++) {

0 commit comments

Comments
 (0)