Skip to content

Commit 62f6d75

Browse files
committed
flex panel gallery
2 parents f32b89f + 3802286 commit 62f6d75

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,81 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34+
const fifteen = inventors.filter(inventor => {
35+
return inventor.year >= 1500 && inventor.year < 1600;
36+
});
37+
// console.table(fifteen);
3438

3539
// Array.prototype.map()
3640
// 2. Give us an array of the inventors' first and last names
41+
const fullNames = inventors.map(inventor => {
42+
return `${inventor.first} ${inventor.last}`;
43+
});
44+
// console.log(fullNames);
3745

3846
// Array.prototype.sort()
3947
// 3. Sort the inventors by birthdate, oldest to youngest
48+
const birthDate = inventors.sort(function(a, b) {
49+
if (a.year > b.year) {
50+
return 1;
51+
}
52+
53+
if (a.year < b.year) {
54+
return -1;
55+
}
56+
57+
// a must be equal to b
58+
return 0;
59+
});
60+
// console.table(birthDate);
4061

4162
// Array.prototype.reduce()
4263
// 4. How many years did all the inventors live?
64+
const totalYears = inventors.reduce((total, inventor) => {
65+
return total += (inventor.passed - inventor.year);
66+
}, 0);
67+
// console.log(totalYears);
4368

4469
// 5. Sort the inventors by years lived
70+
const oldest = inventors.sort((a, b) => {
71+
const lastGuy = a.passed - a.year;
72+
const thisGuy = b.passed - b.year;
73+
return lastGuy > thisGuy ? -1 : 1;
74+
});
75+
// console.table(oldest);
4576

4677
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4778
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
48-
79+
// const category = document.querySelector('.mw-category');
80+
// const links = Array.from(category.querySelectorAll('a'));
81+
//
82+
// const de = links
83+
// .map(link => link.textContent)
84+
// .filter(street => street.includes('de'));
85+
4986

5087
// 7. sort Exercise
5188
// Sort the people alphabetically by last name
89+
const alpha = people.sort((lastOne, nextOne) => {
90+
const [aLast, aFirst] = lastOne.split(', ');
91+
const [bLast, bFirst] = nextOne.split(', ');
92+
return aLast > bLast ? 1 : -1;
93+
});
94+
// console.log(alpha);
5295

5396
// 8. Reduce Exercise
5497
// Sum up the instances of each of these
5598
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
99+
100+
const transportation = data.reduce((obj, item) => {
101+
if (!obj[item]) {
102+
obj[item] = 0;
103+
}
104+
105+
obj[item]++
106+
return obj;
107+
}, {});
108+
console.log(transportation);
56109

57110
</script>
58111
</body>

0 commit comments

Comments
 (0)