Skip to content

Commit f2ba071

Browse files
committed
Almost done with day 4
1 parent 8c3da4b commit f2ba071

File tree

9 files changed

+568
-0
lines changed

9 files changed

+568
-0
lines changed

04 - Array Cardio Day 1/Category_Boulevards in Paris - Wikipedia.html

Lines changed: 279 additions & 0 deletions
Large diffs are not rendered by default.
1.56 KB
Loading

04 - Array Cardio Day 1/Category_Boulevards in Paris - Wikipedia_files/load(1).php

Lines changed: 73 additions & 0 deletions
Large diffs are not rendered by default.

04 - Array Cardio Day 1/Category_Boulevards in Paris - Wikipedia_files/load(2).php

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

04 - Array Cardio Day 1/Category_Boulevards in Paris - Wikipedia_files/load(3).php

Lines changed: 177 additions & 0 deletions
Large diffs are not rendered by default.

04 - Array Cardio Day 1/Category_Boulevards in Paris - Wikipedia_files/load.php

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
1.55 KB
Loading
2.37 KB
Loading

04 - Array Cardio Day 1/index-START.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,61 @@
2727

2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
30+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year <= 1599));
31+
console.table(fifteen);
3032

3133
// Array.prototype.map()
3234
// 2. Give us an array of the inventory first and last names
35+
const fullNames = inventors.map(inventor => inventor.first + ' ' + inventor.last);
36+
console.log(fullNames);
3337

3438
// Array.prototype.sort()
3539
// 3. Sort the inventors by birthdate, oldest to youngest
40+
// const ordered = inventors.sort((a, b) => {
41+
// if(a.year > b.year) {
42+
// return 1;
43+
// } else {
44+
// return -1;
45+
// }
46+
// });
47+
const ordered = inventors.sort((a,b) => a.year > b.year ? 1 : -1);
48+
console.table(ordered);
3649

3750
// Array.prototype.reduce()
3851
// 4. How many years did all the inventors live?
52+
const totalYears = inventors.reduce((total, inventor) => {
53+
return total + (inventor.passed - inventor.year)
54+
}, 0); // 2nd param is the starting value of `total`
55+
console.log(totalYears);
56+
3957

4058
// 5. Sort the inventors by years lived
59+
const oldest = inventors.sort(function(a, b) {
60+
const lastGuyYears = a.passed - a.year
61+
const nextGuyYears = b.passed - b.year
62+
return lastGuyYears > nextGuyYears ? -1 : 1
63+
});
64+
console.table(oldest)
4165

4266
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4367
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
68+
// let category = document.querySelector('.mw-category');
69+
// let links = category.querySelectorAll('a');
70+
// let de = Array.from(links)
71+
// .map(link => link.textContent)
72+
// .filter(streetName => streetName.includes('de'));
4473

4574

4675
// 7. sort Exercise
4776
// Sort the people alphabetically by last name
77+
const alpha = people.sort(function(lastOne, nextOne) {
78+
const [aLast, aFirst] = lastOne.split(', ');
79+
const [bLast, bFirst] = nextOne.split(', ');
80+
return aLast > bLast ? 1 : -1
81+
});
82+
console.log("alpha")
83+
console.log(alpha);
84+
4885

4986
// 8. Reduce Exercise
5087
// Sum up the instances of each of these

0 commit comments

Comments
 (0)