From 7abb2384fa242121d0e51b8c324e64546bd82936 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 27 Feb 2026 20:14:58 +0000 Subject: [PATCH 1/4] complete exercise 1 --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..d86bc7bf 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself({ name, age, favouriteFood }) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From c0ad8e9f25b0dbf9050a0de7d4f549fd5a7a557c Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 27 Feb 2026 20:47:19 +0000 Subject: [PATCH 2/4] hogwarts exercise done --- Sprint-1/destructuring/exercise-2/exercise.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..206fdcc3 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,39 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function logPeopleByHouse(peopleList, houseName) { + peopleList.forEach((person) => { + if (person.house === houseName) { + const { firstName, lastName } = person; + console.log(`${firstName} ${lastName}`); + } + }); +} + +function logTeachersWithPets(peopleList) { + peopleList.forEach((person) => { + if (person.occupation === "Teacher" && person.pet !== null) { + const { firstName, lastName } = person; + console.log(`${firstName} ${lastName}`); + } + }); +} + +// I thought I'd make a more general version which can work for any condition +// though there are no checks for invalid input +function getPersonByPredicate(list, predicate) { + list.forEach((person) => { + if (predicate(person)) { + const { firstName, lastName } = person; + console.log(`${firstName} ${lastName}`); + } + }); +} + +getPersonByPredicate(hogwarts, (person) => person.house === "Gryffindor"); + +getPersonByPredicate( + hogwarts, + (person) => person.occupation === "Teacher" && person.pet +); From e0e402009073271099bea4a317551b2e6caa16f1 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 27 Feb 2026 21:04:12 +0000 Subject: [PATCH 3/4] complete receipt exercise --- Sprint-1/destructuring/exercise-3/exercise.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..0cdd893c 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,18 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(order) { + console.log(`${"QTY".padEnd(8)}${"ITEM".padEnd(20)}TOTAL`); + let total = 0; + order.forEach((item) => { + const { quantity, itemName, unitPricePence } = item; + console.log( + `${String(quantity).padEnd(8)}${String(itemName).padEnd(20)}${((quantity * unitPricePence) / 100).toFixed(2)}` + ); + total += quantity * unitPricePence; + }); + console.log(`\nTotal: ${(total / 100).toFixed(2)}`); +} + +printReceipt(order); From 84ebbefb9180a66155537e3370620759cef9d74d Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 27 Feb 2026 21:09:17 +0000 Subject: [PATCH 4/4] destructuring with default values --- Sprint-1/destructuring/exercise-1/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index d86bc7bf..8a74a963 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,11 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself({ name, age, favouriteFood }) { +function introduceYourself({ + name = "NO NAME", + age = "NO AGE", + favouriteFood = "NO FOOD", +}) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` );