From 36ebed0ca6c7b0633593e0781577bb58dff0ee83 Mon Sep 17 00:00:00 2001 From: Ifham-Hashir Date: Sat, 29 Jun 2024 19:58:24 +0530 Subject: [PATCH 1/2] Complete --- 07 - Array Cardio Day 2/index-START.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..ad96368c63 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,17 +26,31 @@ ]; // 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> 18); + // console.log({isAdult}); + + // Array.prototype.every() // is everyone 19 or older? + // const isNineteen = people.every((person) => ((new Date()).getFullYear()) - person.year > 18); + // console.log({isNineteen}); + // 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((c) => c.id === 823423); + // console.log({comment}); + // Array.prototype.findIndex() // Find the comment with this ID + const index = comments.findIndex((c) => c.id === 823423); + console.log({index}); // delete the comment with the ID of 823423 + comments.splice(index, 1); From 5218a113f4864dff9dd1a71626fc3963fa2ef381 Mon Sep 17 00:00:00 2001 From: Ifham-Hashir Date: Sat, 29 Jun 2024 19:59:23 +0530 Subject: [PATCH 2/2] Complete --- 04 - Array Cardio Day 1/index-START.html | 33 +++++++++++++++++++++- 04 - Array Cardio Day 1/index.html | 35 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 04 - Array Cardio Day 1/index.html diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..d8292bbb68 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,29 +38,60 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + // const born = inventors.filter((i) => i.year < 1600 && i.year > 1499); + // console.log(born); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + // const mappedArr = inventors.map((i) => [i.first, i.last]); + // console.log(mappedArr); + // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + // const sorted = inventors.sort((a,b) => a.year > b.year ? 1 : -1); + // console.table(sorted); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + // const totalYears = inventors.reduce((total, inventor) => total + (inventor.passed - inventor.year),0); + // console.log(totalYears); // 5. Sort the inventors by years lived + // const sortYears = inventors.sort((a,b) => a.passed - a.year > b.passed - b.year ? -1 : 1); + // console.table(sortYears); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name - // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + //https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + // const category = document.querySelector(".mw-category"); + // const links = [...category.querySelectorAll("a")]; + // const de = links + // .map(link => link.textContent) + // .filter(streetName => streetName.includes('de')); // 7. sort Exercise // Sort the people alphabetically by last name + // const sortName = people.sort((a,b) => { + // const [aLast, aFirst] = a.split(', '); + // const [bLast, bFirst] = b.split(', '); + // return aLast > bLast ? 1 : -1; + // }); + // console.table(sortName); // 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]){ + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + console.log(transport); + diff --git a/04 - Array Cardio Day 1/index.html b/04 - Array Cardio Day 1/index.html new file mode 100644 index 0000000000..ac1c09e8a3 --- /dev/null +++ b/04 - Array Cardio Day 1/index.html @@ -0,0 +1,35 @@ + + + + + + Document + + + + + \ No newline at end of file