diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..74ecc60903 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -38,17 +38,26 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's - + + let invent_filtered = inventors.filter(i => (i['year'] < 1600 && i['year'] > 1499) ? i : null); + // Array.prototype.map() // 2. Give us an array of the inventors first and last names + let names = inventors.map((word, i) => word.first, word.last) // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + let age_sort = inventors.sort((a,b) => a.year - b.year); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + let years_lived = inventors.reduce((total, inventor) => { return total + (inventor.passed - inventor.year) }, 0); + // 5. Sort the inventors by years lived + + + // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris @@ -61,6 +70,17 @@ // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + let l2 = data.reduce((acc, item) => { + if(!(acc[item])) { + acc[item] = 1; + } else { + acc[item] = acc[item] + 1; + } + + return acc; +}, {}) + + diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 4ca34c7536..fea5f807d5 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -29,14 +29,25 @@ // Array.prototype.some() // is at least one person 19 or older? // Array.prototype.every() // is everyone 19 or older? + const any_adults = people.some(person => ((new Date()).getFullYear()) - person.year >= 19 + ); + + const all_adults = people.every(people => ((new Date()).getFullYear()) - people.year >= 19); + // 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); + // 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(comments.splice(index, 1)); +