From 8dc05b72ac8deb3d4da091324ff1673699834ab2 Mon Sep 17 00:00:00 2001 From: EslamSalem Date: Tue, 31 Dec 2024 16:53:11 +0200 Subject: [PATCH 1/2] solved --- 04 - Array Cardio Day 1/index-START.html | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..5654752860 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,28 +38,61 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter((inventor) => (inventor.year >= 1500 && inventor.year < 1600)); + console.table(fifteen); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const names = inventors.map((inventor) => `${inventor.first} ${inventor.last}`); + console.table(names); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + inventors.sort((a, b) => b.year - a.year); + console.table(inventors); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const sumOfAges = inventors.reduce((sum, inventor) => sum + (inventor.passed - inventor.year), 0); + console.log(sumOfAges); // 5. Sort the inventors by years lived + inventors.sort((a, b) => { + return((a.passed - a.year) - (b.passed - b.year)); + }); + console.table(inventors); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + // const category = document.querySelector('.mw-category'); + // const links = [...category.querySelectorAll('a')]; + // const linkNames = links + // .map(link => link.textContent) + // .filter(name => name.includes('de')); + // 7. sort Exercise // Sort the people alphabetically by last name + console.table(people); + people.sort((a, b) => { + const [alast, afirst] = a.split(', '); + const [blast, bfirst] = b.split(', '); + return afirst.localeCompare(bfirst); + }); + console.table(people); // 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' ]; + const transport = data.reduce((obj, item) => { + if (obj[item] === undefined) { + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + console.log(transport); From 7574ec4af01c1431268287be0f206c39f687c05e Mon Sep 17 00:00:00 2001 From: EslamSalem Date: Tue, 31 Dec 2024 17:57:20 +0200 Subject: [PATCH 2/2] solved --- 07 - Array Cardio Day 2/index-START.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..22a48dace0 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -27,16 +27,26 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const isAdult = people.some((person) => (new Date().getFullYear() - person.year) >= 19); + console.log(isAdult); // Array.prototype.every() // is everyone 19 or older? + const isAllAdult = people.every((person) => (new Date().getFullYear() - person.year) >= 19); + console.log(isAllAdult); // 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 + const comment = comments.find((comment => comment.id === 823423)); + console.log(comment); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 - + console.table(comments); + const index = comments.findIndex((comment => comment.id === 823423)); + comments.splice(index, 1); + console.table(comments); +