Skip to content

Commit 8bf74d4

Browse files
committed
finished challenge wesbos#4
1 parent b379d16 commit 8bf74d4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,83 @@
3737

3838
// Array.prototype.filter()
3939
// 1. Filter the list of inventors for those who were born in the 1500's
40+
const fifteen = inventors.filter(function(inventor) {
41+
if(inventor.year >= 1500 && inventor.year <= 1600) {
42+
return true;
43+
}
44+
})
45+
// console.table(fifteen);
46+
// console.log(fifteen)
4047

4148
// Array.prototype.map()
4249
// 2. Give us an array of the inventors first and last names
50+
const fullName = inventors.map(inventor => inventor.first + ' ' + inventor.last)
51+
// console.log(fullName)
52+
// console.table(fullName);
4353

4454
// Array.prototype.sort()
4555
// 3. Sort the inventors by birthdate, oldest to youngest
56+
// const sortBirthDate = inventors.sort(function(a, b) {
57+
// if(a.year >b.year) {
58+
// return 1;
59+
// } else {
60+
// return -1;
61+
// }
62+
// })
63+
64+
const sortBirthDate = inventors.sort((a, b) => a.year > b.year ? 1 : -1);
65+
// console.table(sortBirthDate)
66+
// console.log(sortBirthDate)
4667

4768
// Array.prototype.reduce()
4869
// 4. How many years did all the inventors live all together?
70+
const totalYears = inventors.reduce((total, inventor) => {
71+
return total + (inventor.passed - inventor.year);
72+
}, 0)
73+
// console.log(totalYears)
4974

5075
// 5. Sort the inventors by years lived
76+
const oldest = inventors.sort(function(a, b) {
77+
const lastGuy = a.passed - a.year;
78+
const nextGuy = b.passed - b.year;
79+
return lastGuy > nextGuy ? -1 : 1;
80+
// if(lastGuy > nextGuy) {
81+
// return -1;
82+
// } else {
83+
// return 1;
84+
// }
85+
} )
86+
// console.table(oldest)
5187

5288
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5389
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
90+
// const category = document.querySelector('.mw-category');
91+
// const links = Array.from(category.querySelectorAll('a'))
92+
// const de = links
93+
// .map(link => link.textContent)
94+
// .filter(streetName => streetName.includes('de'));
95+
5496

5597

5698
// 7. sort Exercise
5799
// Sort the people alphabetically by last name
100+
const alpha = people.sort((lastOne, nextOne) => {
101+
const [aLast, aFirst] = lastOne.split(', ')
102+
const [bLast, bFirst] = nextOne.split(', ')
103+
return aLast > bLast ? 1 : -1;
104+
})
105+
// console.log(alpha)
58106

59107
// 8. Reduce Exercise
60108
// Sum up the instances of each of these
61109
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
110+
const transportation = data.reduce(function(obj, item) {
111+
if(!obj[item]) {
112+
obj[item] = 0;
113+
}
114+
obj[item]++;
115+
return obj;
116+
}, {})
62117

63118
</script>
64119
</body>

0 commit comments

Comments
 (0)