diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..cfd5c98349 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,25 @@ diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 21bec96e8c..a9254b5afb 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -13,18 +13,18 @@ // Some data we can work with const inventors = [ - { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 }, - { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 }, - { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 }, - { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 }, - { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 }, - { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 }, - { first: 'Max', last: 'Planck', year: 1858, passed: 1947 }, - { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 }, - { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 }, - { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 }, - { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 }, - { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 } + { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 }, + { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 }, + { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 }, + { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 }, + { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 }, + { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 }, + { first: 'Max', last: 'Planck', year: 1858, passed: 1947 }, + { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 }, + { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 }, + { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 }, + { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 }, + { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 } ]; const people = [ @@ -37,29 +37,59 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const old = inventors.filter(p => 1500 <= p.year && p.year < 1600); + console.table(old); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const names = inventors.map(p => `${p.first} ${p.last}`); + console.log(names); // 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 sumAge = inventors.reduce((acc, a) => acc + a.passed - a.year, 0); + console.log(sumAge); // 5. Sort the inventors by years lived - + const sorted2 = inventors.sort((a,b) => + a.passed-a.year > b.passed-b.year ? -1 : 1); + console.table(sorted2); + // 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 links = Array.from(document.querySelectorAll('.mw-category a')); + const de = links + .map(link => link.textContent) + .filter(street => street.includes('de')); // 7. sort Exercise // Sort the people alphabetically by last name + const sorted3 = people.sort((a,b) => a > b ? 1 : -1); + console.table(sorted3); + + + const sorted4 = people.sort((a,b) => { + const [al, af] = a.split(', '); + const [bl, bf] = b.split(', '); + return al > bl ? 1: -1; + }); + // 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 dataSum = data.reduce((acc, a) => { + if (!acc[a]) acc[a] = 0; + acc[a]++; + return acc; + },{}); + console.log(dataSum); + diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..0fa5c967b2 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,25 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const someone = people.some(a => (new Date()).getFullYear() - a.year >= 19); + console.log(someone); + // Array.prototype.every() // is everyone 19 or older? + const everyone = people.every(a => (new Date()).getFullYear() - a.year >= 19); + console.log(everyone); // 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 theOne = comments.find(a => a.id === 823423); + console.log(theOne); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const index = comments.findIndex(a => a.id === 823423); + comments.splice(index,1); + console.table(comments); diff --git a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html index 7bd5931e01..b137f98db0 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -40,9 +40,21 @@ } - +