diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..a8c09637b6 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,29 +38,40 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's - + const fiveInventors = inventors.filter(item => item.year <= 1599 && item.year >= 1500); + console.table(fiveInventors); // Array.prototype.map() // 2. Give us an array of the inventors first and last names - + const firstLast = inventors.map(inventor => `${inventor.first} ${inventor.last}`); + console.log(firstLast); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest - + const orderedArrayByAge = inventors.sort((a, b) => a.year - b.year); + console.log(orderedArrayByAge); // 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 orderedArrayYearsLived = inventors.sort((a,b) => (a.passed - a.year) - (b.passed - b.year)); + console.table(orderedArrayYearsLived); // 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-content-ltr"); + const links = [...category.querySelectorAll("a")]; + const filtered = links + .map(link => link.textContent) + .filter(streetName => streetName.includes("de")); */ // 7. sort Exercise // Sort the people alphabetically by last name - + console.table(people.sort()); // 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) => ( + obj[item] = (obj[item] || 0) + 1, obj + ), {}); + console.log(transportation); diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..05f1a52311 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -27,16 +27,22 @@ // 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 isEveryoneAdult = people.every(person => new Date().getFullYear() - person.year >= 19); + console.log({isEveryoneAdult}); // 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 findId = comments.find(comment => comment.id === 823423); + console.log(findId); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 - + const index = comments.findIndex(num => num.id === 823423); + console.log(index); + comments.splice(index, 1);