From b895d159374196b4f2b6e8e85d1e0c67fd5dafc5 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 8 Apr 2026 21:22:59 +0100 Subject: [PATCH 1/8] defined destructing syntax and updated function parameter in exercise.js file --- Sprint-1/destructuring/exercise-1/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..2e01b341 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -3,10 +3,10 @@ const personOne = { age: 34, favouriteFood: "Spinach", }; - +let {name, age, favouriteFood} = personOne // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself(aboutMe){ console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From b9a00087461178d39e27251362b33add45fd4d45 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 8 Apr 2026 22:54:35 +0100 Subject: [PATCH 2/8] implement function to extract data from arrays of object through destructuring in exercise2 --- Sprint-1/destructuring/exercise-2/exercise.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..f83e9706 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,10 @@ let hogwarts = [ occupation: "Teacher", }, ]; +function gryffindors(hogwartsArray){ + let houseOfGryffindor = hogwartsArray.filter( (item) => item.house === "Gryffindor"); + houseOfGryffindor.forEach( ({firstName, lastName}) => { +console.log(`${firstName} ${lastName}`); + }) +} +gryffindors(hogwarts); From e80bba0d5f3fa46a9186deef36087bf38d48b764 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 8 Apr 2026 23:41:56 +0100 Subject: [PATCH 3/8] implement function to output names of teachers with pets using destructuring --- Sprint-1/destructuring/exercise-2/exercise.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index f83e9706..d35191e2 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,10 +70,20 @@ let hogwarts = [ occupation: "Teacher", }, ]; -function gryffindors(hogwartsArray){ - let houseOfGryffindor = hogwartsArray.filter( (item) => item.house === "Gryffindor"); - houseOfGryffindor.forEach( ({firstName, lastName}) => { -console.log(`${firstName} ${lastName}`); - }) +function gryffindors(hogwartsArray) { + let houseOfGryffindor = hogwartsArray.filter( + (item) => item.house === "Gryffindor" + ); + houseOfGryffindor.forEach(({ firstName, lastName }) => { + console.log(`${firstName} ${lastName}`); + }); } gryffindors(hogwarts); + +function teachersWithPets(hogwartsArray) { + let namesOfTeachers = hogwartsArray.filter((item) => item.pet !== null); + namesOfTeachers.forEach(({ firstName, lastName }) => { + console.log(`${firstName} ${lastName}`); + }); +} +teachersWithPets(hogwarts); \ No newline at end of file From baa55c69db91ecab9a2a66b340ebf5db86be10f3 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 8 Apr 2026 23:52:35 +0100 Subject: [PATCH 4/8] update function to output names of teachers with pets using destructuring --- Sprint-1/destructuring/exercise-2/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index d35191e2..c22d5b08 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -81,7 +81,7 @@ function gryffindors(hogwartsArray) { gryffindors(hogwarts); function teachersWithPets(hogwartsArray) { - let namesOfTeachers = hogwartsArray.filter((item) => item.pet !== null); + let namesOfTeachers = hogwartsArray.filter((item) => item.pet !== null && item.occupation === "Teacher"); namesOfTeachers.forEach(({ firstName, lastName }) => { console.log(`${firstName} ${lastName}`); }); From ffdb24fa339b60450adb29c43d1d8609b9d34b1e Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 9 Apr 2026 00:26:56 +0100 Subject: [PATCH 5/8] implement order function with destructured data --- Sprint-1/destructuring/exercise-3/exercise.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..10b9d4a1 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,13 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +function orders(orderItems) { + // let total = 0; + console.log("QTY ITEM TOTAL"); + orderItems.forEach(({ quantity, itemName, unitPricePence }) => { + console.table(`${quantity} ${itemName} ${unitPricePence}`); + }); +} + +orders(order); +console.table(order) \ No newline at end of file From 673af3b75fabd50f56d0dcc8ff4cad099ceba30c Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 9 Apr 2026 19:15:44 +0100 Subject: [PATCH 6/8] update order function to print order items in table like format --- Sprint-1/destructuring/exercise-3/exercise.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 10b9d4a1..ab4aad6b 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,12 +7,21 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; function orders(orderItems) { - // let total = 0; - console.log("QTY ITEM TOTAL"); + const header = `${"QTY".padEnd(5)}${"ITEM".padEnd(20)}${"TOTAL (£)".padStart(10)}`; + console.log(header); orderItems.forEach(({ quantity, itemName, unitPricePence }) => { - console.table(`${quantity} ${itemName} ${unitPricePence}`); - }); + const totalPounds = ((quantity * unitPricePence) / 100).toFixed(2); + const row = `${String(quantity).padEnd(5)}${itemName.padEnd(20)}${totalPounds.padStart(10)}`; + console.log(row); + +}); + const grandTotal = orderItems.reduce( + (sum, { quantity, unitPricePence }) => { + return sum + quantity * unitPricePence; + }, + 0 + ); + console.log(`Total: £${(grandTotal/100).toFixed(2)}`); } orders(order); -console.table(order) \ No newline at end of file From f87e7eb9683092ab2225fa50470d1183e2bd0b6e Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 10 Apr 2026 18:26:11 +0100 Subject: [PATCH 7/8] format order function code --- Sprint-1/destructuring/exercise-3/exercise.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index ab4aad6b..705f22da 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,21 +7,21 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; function orders(orderItems) { - const header = `${"QTY".padEnd(5)}${"ITEM".padEnd(20)}${"TOTAL (£)".padStart(10)}`; - console.log(header); + const header = `${"QTY".padEnd(5)}${"ITEM".padEnd(20)}${"TOTAL (£)".padStart( + 10 + )}`; + console.log(header); orderItems.forEach(({ quantity, itemName, unitPricePence }) => { - const totalPounds = ((quantity * unitPricePence) / 100).toFixed(2); - const row = `${String(quantity).padEnd(5)}${itemName.padEnd(20)}${totalPounds.padStart(10)}`; - console.log(row); - -}); - const grandTotal = orderItems.reduce( - (sum, { quantity, unitPricePence }) => { - return sum + quantity * unitPricePence; - }, - 0 - ); - console.log(`Total: £${(grandTotal/100).toFixed(2)}`); + const totalPounds = ((quantity * unitPricePence) / 100).toFixed(2); + const row = `${String(quantity).padEnd(5)}${itemName.padEnd( + 20 + )}${totalPounds.padStart(10)}`; + console.log(row); + }); + const grandTotal = orderItems.reduce((sum, { quantity, unitPricePence }) => { + return sum + quantity * unitPricePence; + }, 0); + console.log(`Total: £${(grandTotal / 100).toFixed(2)}`); } orders(order); From b710740875dcb545aa22e62e7bd79300f4386a3a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 10 Apr 2026 18:46:39 +0100 Subject: [PATCH 8/8] refactor hogwarts function implementation for better performance --- Sprint-1/destructuring/exercise-2/exercise.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index c22d5b08..230e546b 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -71,19 +71,19 @@ let hogwarts = [ }, ]; function gryffindors(hogwartsArray) { - let houseOfGryffindor = hogwartsArray.filter( - (item) => item.house === "Gryffindor" - ); - houseOfGryffindor.forEach(({ firstName, lastName }) => { - console.log(`${firstName} ${lastName}`); + hogwartsArray.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } }); } gryffindors(hogwarts); function teachersWithPets(hogwartsArray) { - let namesOfTeachers = hogwartsArray.filter((item) => item.pet !== null && item.occupation === "Teacher"); - namesOfTeachers.forEach(({ firstName, lastName }) => { - console.log(`${firstName} ${lastName}`); + hogwartsArray.forEach(({ firstName, lastName, pet, occupation }) => { + if (pet !== null && occupation === "Teacher") { + console.log(`${firstName} ${lastName}`); + } }); } -teachersWithPets(hogwarts); \ No newline at end of file +teachersWithPets(hogwarts);