From 7ad53f990790ed7b6bfb29140ba760cf9b176ce9 Mon Sep 17 00:00:00 2001 From: adnan-kibria Date: Sat, 25 Oct 2025 12:30:41 +0600 Subject: [PATCH 1/2] Exercise completed but some are undone --- 04 - Array Cardio Day 1/index-START.html | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..fe686f64e3 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,17 +38,40 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const filteredInventors = inventors.filter( + (inventorsYear) => inventorsYear.year >= 1500 && inventorsYear.year < 1600 + ) + console.log(filteredInventors); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const inventorsFirstLastNames = inventors.map( + (names) => `${names.first} ${names.last}` + ) + console.log(inventorsFirstLastNames); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const inventorsBirthDateDesc = inventors.sort( + (oldest, newest) => oldest.year < newest.year ? 1 : -1 + ) + console.log(inventorsBirthDateDesc); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const sumOfInventorsLifeSpan = inventors.reduce( + (total, inventorsAge) => { + return total + (inventorsAge.passed - inventorsAge.year); + }, 0); + console.log(sumOfInventorsLifeSpan); // 5. Sort the inventors by years lived + let inventorsLifeSpan = []; + inventors.forEach( + (years) => inventorsLifeSpan.push(years.passed - years.year) + ) + const yearLived = inventorsLifeSpan.sort((a,b) => a > b ? 1 : -1); + console.log(yearLived); // 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,10 +79,29 @@ // 7. sort Exercise // Sort the people alphabetically by last name + const sortPeopleByLastName = people.sort( + (a,b) => {const aa = a.split(', ')[0]; + const bb = b.split(', ')[0]; + return aa > bb ? 1 : -1; + } + ) + console.log(sortPeopleByLastName); // 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 sumOfInstances = data.reduce( + (object, items) => { + if(object[items]){ + object[items] = object[items] +1; + } + else{ + object[items] = 1; + } + return object; + }, {}) + console.log(sumOfInstances); + From c36b788432a1641ed78754c8326b1b24a4d70441 Mon Sep 17 00:00:00 2001 From: adnan-kibria Date: Sat, 25 Oct 2025 13:02:34 +0600 Subject: [PATCH 2/2] exercise is completed --- 07 - Array Cardio Day 2/index-START.html | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..328002186d 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -28,14 +28,39 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? // Array.prototype.every() // is everyone 19 or older? + const currentYear = new Date().getFullYear(); + const someAge = people.some( + (age) => { + age = currentYear - age.year; + return age >= 19 ? true : false; + } + ) + console.log(someAge); + const everyAge = people.every( + (age) => { + age = currentYear - age.year; + return age >= 19 ? true : false; + } + ) + console.log(everyAge); // 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 findCommentById = comments.find( + (id) => id.id === 823423 + ); + console.log(findCommentById); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const findCommentByIndex = comments.findIndex( + (index) => index.id == 823423 + ) + console.log(findCommentByIndex); + comments.splice(1, 1); + console.log(comments);