From 04e8925eb9d51dc13f5f04a4fe69aee36c8b3c9b Mon Sep 17 00:00:00 2001 From: Adam Erstad Date: Mon, 26 Feb 2024 00:47:17 -0800 Subject: [PATCH 1/2] Exercise 4 Done --- .hintrc | 8 ++++++++ 04 - Array Cardio Day 1/index-START.html | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .hintrc diff --git a/.hintrc b/.hintrc new file mode 100644 index 0000000000..5b18485f20 --- /dev/null +++ b/.hintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "development" + ], + "hints": { + "meta-viewport": "off" + } +} \ No newline at end of file diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..874cf1ad04 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,17 +38,27 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + let inventors1500s = inventors.filter(item => item.year >= 1500 && item.year < 1600); + console.table(inventors1500s); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + let inventorsNames = inventors.map(item => `${item.first} ${item.last}`) + console.log(inventorsNames); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + let inventorsSortedByBirth = inventors.sort((a, b) => a.year > b.year ? 1 : -1); + console.table(inventorsSortedByBirth); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + let inventorsYearsSum = inventors.reduce( (total, item) => total + item.passed - item.year, 0); + console.log(inventorsYearsSum); // 5. Sort the inventors by years lived + let inventorsSortedByYearsLived = inventors.sort((a, b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1); + console.table(inventorsSortedByYearsLived); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris @@ -56,11 +66,22 @@ // 7. sort Exercise // Sort the people alphabetically by last name + let peopleSortedByLastName = people.sort( (a, b) => { + let aLastName = a.split(', ')[0]; + let bLastName = b.split(', ')[0]; + return aLastName > bLastName ? 1 : -1; + }) + console.log(peopleSortedByLastName); // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; - + console.log(data); + console.log(`Car Instances: ${data.reduce((total, item) => total + (item === 'car'), 0)}`); + console.log(`Truck Instances: ${data.reduce((total, item) => total + (item === 'truck'), 0)}`); + console.log(`Bike Instances: ${data.reduce((total, item) => total + (item === 'bike'), 0)}`); + console.log(`Walk Instances: ${data.reduce((total, item) => total + (item === 'walk'), 0)}`); + console.log(`Van Instances: ${data.reduce((total, item) => total + (item === 'van'), 0)}`); From c9dc3e4dd9933b18f58d019763ee9d2c2dc77d89 Mon Sep 17 00:00:00 2001 From: Adam Erstad Date: Mon, 26 Feb 2024 01:08:37 -0800 Subject: [PATCH 2/2] Exercise 7 Done --- 07 - Array Cardio Day 2/index-START.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..274e508043 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -28,14 +28,25 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? // Array.prototype.every() // is everyone 19 or older? + let is19orOlder = people.some( item => 2023 - item.year >= 19) ? "Yes" : "No"; + let isAll19orOlder = people.every(item => 2023 - item.year >= 19) ? "Yes" : "No"; + console.log(`Is someone 19 or older? ${is19orOlder}. Is everyone 19 or older? ${isAll19orOlder}.`); // Array.prototype.find() // Find is like filter, but instead returns just the one you are looking for // find the comment with the ID of 823423 + let comment = comments.find(item => item.id == 823423); + console.log(`The comment '${comment.text}' has an id of ${comment.id}.`); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + let index = comments.findIndex(item => item.id == 823423); + comments[index].text = ''; + comments.sort((a, b) => a.text === '' ? -1 : 1); + comments.shift(); + console.log('It has now been deleted due to violating multiple rules.'); + console.table(comments);