From 279ff65c3db8e6e03ce492aa175ed76be238814a Mon Sep 17 00:00:00 2001 From: AhmedWaleedElFar Date: Tue, 9 Sep 2025 07:01:14 +0300 Subject: [PATCH 1/2] Feat: Array Cardio Day 1 Done! --- 04 - Array Cardio Day 1/index-START.html | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..0dc1f2c0d3 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,28 +38,67 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const bornFifteens = inventors.filter((inventor) => inventor.year >= 1500 && inventor.year < 1600); + console.table(bornFifteens); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const fullNames = inventors.map((inventor) => `${inventor.first} ${inventor.last}`); + console.log(fullNames); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const orderedBirth = inventors.sort((inv1, inv2) => inv1.year - inv2.year) + console.table(orderedBirth) + // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const sum = inventors.reduce((total, inventor) => { + total += inventor.passed - inventor.year; + return total; + }, 0) + console.log(sum) + // 5. Sort the inventors by years lived + const sortYearsLived = inventors.sort((inv1, inv2) => { + inv1Years = inv1.passed - inv1.year; + inv2Years = inv2.passed - inv2.year; + return inv1Years - inv2Years > 0 ? -1 : 1 + }) + console.table(sortYearsLived) // 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 = Array.from(category.querySelectorAll("a")) + // const de = links + // .map(link => link.textContent) + // .filter(streetName => streetName.includes("de")) + // console.log(de) // 7. sort Exercise // Sort the people alphabetically by last name + const sortedLast = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', ') + const [bLast, bFirst] = nextOne.split(', ') + return aLast > bLast ? 1 : -1 + }) + console.table(sortedLast) // 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 transportation = data.reduce((obj, item) => { + if(!obj[item]){ + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}) + console.log(transportation) From 47741bf4d256c55e3f766f0ebecfe5dc1beee9ff Mon Sep 17 00:00:00 2001 From: AhmedWaleedElFar Date: Tue, 9 Sep 2025 07:09:36 +0300 Subject: [PATCH 2/2] Feat: Array Cardio Day 2 Done! --- 07 - Array Cardio Day 2/index-START.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..387192e442 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -27,15 +27,25 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const someCheck = people.some(person => ((new Date).getFullYear() - person.year >= 19)) + console.log(someCheck) + // Array.prototype.every() // is everyone 19 or older? + const everyCheck = people.every(person => (new Date).getFullYear() - person.year >= 19) + console.log(everyCheck) // 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 findCheck = comments.find(comment => comment.id == 823423) + console.log(findCheck) // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const index = comments.findIndex(comment => comment.id == 823423) + comments.splice(index, 1) + console.log(comments)