From 064ea24ee94957661df02ea1830155690e80bf6a Mon Sep 17 00:00:00 2001 From: Pedro Ricciardi Date: Thu, 15 Feb 2024 09:49:09 +0000 Subject: [PATCH 1/4] exercise 1 done --- array-destructuring/exercise-1/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..b6662f57 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,7 +4,8 @@ const personOne = { favouriteFood: "Spinach", }; -function introduceYourself(___________________________) { +function introduceYourself(person) { + let { name, age, favouriteFood } = person; console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From c296e7654d1d99eeaab6b443e795ddaf14fbf15d Mon Sep 17 00:00:00 2001 From: Pedro Ricciardi Date: Thu, 15 Feb 2024 10:01:46 +0000 Subject: [PATCH 2/4] exercise 2 done --- array-destructuring/exercise-2/exercise.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..34ffd251 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,22 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function showPeopleBelongIn(array, houseName) { + const filteredArray = array.filter((person) => person.house === houseName); + filteredArray.forEach((person) => { + const {firstName, lastName} = person; + console.log(`${firstName} ${lastName}`); + }) +} + +function showTeachersWithPets(array) { + const filteredArray = array.filter((person) => person.pet !== null && person.occupation === "Teacher"); + filteredArray.forEach((person) => { + const {firstName, lastName} = person + console.log(`\n${firstName} ${lastName}`); + }) +} + +showPeopleBelongIn(hogwarts, "Gryffindor"); +showTeachersWithPets(hogwarts); \ No newline at end of file From b38addece5e3b9203cf90a20345ea1cd37da26eb Mon Sep 17 00:00:00 2001 From: Pedro Ricciardi Date: Thu, 15 Feb 2024 10:16:46 +0000 Subject: [PATCH 3/4] exercise 3 done --- array-destructuring/exercise-3/exercise.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..e740ec55 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,29 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +function makeReceipt(order) { + let total = 0; + let itemNameArray = [] + let quantityArray = [] + let itemPriceArray = [] + + order.map((item) => { + const { itemName, quantity, unitPrice } = item; + total += quantity * unitPrice; + quantityArray.push(quantity); + itemNameArray.push(itemName); + itemPriceArray.push(quantity * unitPrice); + }) + + console.log(`QTY ITEM TOTAL`); + + itemNameArray.forEach((itemName, index) => { + const spaces = " ".repeat(20 - itemName.length); + console.log(`${quantityArray[index]} ${itemName}${spaces}$${itemPriceArray[index].toFixed(2)}`); + }) + + console.log(`\nTotal: $${total.toFixed(2)}`); +} + +makeReceipt(order); \ No newline at end of file From cfe8eb94d907739ec51f97e71399c88b9a7f764b Mon Sep 17 00:00:00 2001 From: Pedro Ricciardi Date: Wed, 13 Mar 2024 10:00:07 +0000 Subject: [PATCH 4/4] adjustments requested by Jed Thompson --- array-destructuring/exercise-1/exercise.js | 2 +- array-destructuring/exercise-2/exercise.js | 18 +++++++++--------- array-destructuring/exercise-3/exercise.js | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index b6662f57..04fd7aae 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -5,7 +5,7 @@ const personOne = { }; function introduceYourself(person) { - let { name, age, favouriteFood } = person; + const { name, age, favouriteFood } = person; console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index 34ffd251..ddf2d2ae 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -71,21 +71,21 @@ let hogwarts = [ }, ]; -function showPeopleBelongIn(array, houseName) { - const filteredArray = array.filter((person) => person.house === houseName); - filteredArray.forEach((person) => { - const {firstName, lastName} = person; +function showPeopleBelongIn(people, houseName) { + const peopleInHouse = people.filter((person) => person.house === houseName); + peopleInHouse.forEach((person) => { + const { firstName, lastName } = person; console.log(`${firstName} ${lastName}`); }) } -function showTeachersWithPets(array) { - const filteredArray = array.filter((person) => person.pet !== null && person.occupation === "Teacher"); - filteredArray.forEach((person) => { - const {firstName, lastName} = person +function showTeachersWithPets(people) { + const teachersWithPets = people.filter((person) => person.pet !== null && person.occupation === "Teacher"); + teachersWithPets.forEach((teacherWithPet) => { + const { firstName, lastName } = teacherWithPet; console.log(`\n${firstName} ${lastName}`); }) } showPeopleBelongIn(hogwarts, "Gryffindor"); -showTeachersWithPets(hogwarts); \ No newline at end of file +showTeachersWithPets(hogwarts); diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index e740ec55..29f01393 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -9,11 +9,11 @@ let order = [ function makeReceipt(order) { let total = 0; - let itemNameArray = [] - let quantityArray = [] - let itemPriceArray = [] + const itemNameArray = [] + const quantityArray = [] + const itemPriceArray = [] - order.map((item) => { + order.forEach((item) => { const { itemName, quantity, unitPrice } = item; total += quantity * unitPrice; quantityArray.push(quantity);