diff --git a/04 - Array Cardio Day 1/index-FINISHED.html b/04 - Array Cardio Day 1/index-FINISHED.html index 10b655820a..9cc4f46ce0 100644 --- a/04 - Array Cardio Day 1/index-FINISHED.html +++ b/04 - Array Cardio Day 1/index-FINISHED.html @@ -40,13 +40,10 @@ // 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 inventor 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 ordered = inventors.sort(function(a, b) { @@ -58,32 +55,29 @@ // }); const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1); - console.table(ordered); // Array.prototype.reduce() // 4. How many years did all the inventors live? const totalYears = inventors.reduce((total, inventor) => { return total + (inventor.passed - inventor.year); }, 0); - - console.log(totalYears); - + // 5. Sort the inventors by years lived const oldest = inventors.sort(function(a, b) { const lastInventor = a.passed - a.year; const nextInventor = b.passed - b.year; return lastInventor > nextInventor ? -1 : 1; }); - console.table(oldest); + // 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 = Array.from(category.querySelectorAll('a')); - // const de = links - // .map(link => link.textContent) - // .filter(streetName => streetName.includes('de')); + // 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')); // 7. sort Exercise // Sort the people alphabetically by last name @@ -92,7 +86,7 @@ const [bLast, bFirst] = nextOne.split(', '); return aLast > bLast ? 1 : -1; }); - console.log(alpha); + // 8. Reduce Exercise // Sum up the instances of each of these @@ -106,8 +100,6 @@ return obj; }, {}); - console.log(transportation); - diff --git a/07 - Array Cardio Day 2/index-FINISHED.html b/07 - Array Cardio Day 2/index-FINISHED.html index 0d99beba99..9ed4603eef 100644 --- a/07 - Array Cardio Day 2/index-FINISHED.html +++ b/07 - Array Cardio Day 2/index-FINISHED.html @@ -34,36 +34,38 @@ // } // }); - const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); + // const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); - console.log({isAdult}); - // Array.prototype.every() // is everyone 19? + // console.log({isAdult}); + // // Array.prototype.every() // is everyone 19? - const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); - console.log({allAdults}); + // const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); + // console.log({allAdults}); // 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); + const comment = comments.find(comment => comment.id === 823423); - console.log(comment); + console.log(comment); // 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); - console.log(index); + const index = comments.findIndex(comment => comment.id === 823423) + // comments.splice(index, 1); + // console.table(comments); - // comments.splice(index, 1); const newComments = [ - ...comments.slice(0, index), - ...comments.slice(index + 1) + ...comments.slice(0, index), + ...comments.slice(index + 1), ]; + console.table(newComments); + diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..25bcefc713 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -24,19 +24,26 @@ { text: 'Ramen is my fav food ever', id: 123523 }, { text: 'Nice Nice Nice!', id: 542328 } ]; - + // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? - // Array.prototype.every() // is everyone 19 or older? + const isAdult = people.some(person => ((new Date()). + getFullYear()) - person.year >= 19 ); + // Array.prototype.every() // is everyone 19 or older? + const allAdult = people.every(person => ((new Date()). + getFullYear()) - person.year >= 19 ); + console.log({allAdult}); // 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 - + const index = comments.findIndex(comment => comment.id === 823423); + console.log(index);