Skip to content

Commit 9606290

Browse files
author
=
committed
JS#30 wesbos#4 completed
1 parent 6d3e0cd commit 9606290

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

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

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Array Cardio 💪</title>
67
</head>
8+
79
<body>
810
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
911
<script>
@@ -34,32 +36,69 @@
3436
'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose',
3537
'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank'
3638
];
37-
39+
3840
// Array.prototype.filter()
3941
// 1. Filter the list of inventors for those who were born in the 1500's
42+
//filter returns the only results where the condition is satisfied
43+
console.table(inventors.filter(inventor => inventor.year >= 1500 && inventor.year <= 1599))
4044

4145
// Array.prototype.map()
4246
// 2. Give us an array of the inventors first and last names
47+
// map returns the array equal to the size of the parent array
48+
console.log(inventors.map(inventor => `${inventor.first} ${inventor.last}`))
4349

44-
// Array.prototype.sort()
50+
// Array.prot otype.sort()
4551
// 3. Sort the inventors by birthdate, oldest to youngest
52+
console.table(inventors.sort((a, b) => a.year > b.year ? 1 : -1));
4653

4754
// Array.prototype.reduce()
4855
// 4. How many years did all the inventors live all together?
56+
const totalYears = inventors.reduce((total, inventor) => {
57+
return total + (inventor.passed - inventor.year);
58+
}, 0);
59+
console.log(totalYears);
4960

5061
// 5. Sort the inventors by years lived
62+
const oldest = inventors.sort((a,b)=>{
63+
const A = a.passed - a.year;
64+
const B = b.passed - b.year;
65+
return A > B ? -1 : 1;
66+
})
67+
console.table(oldest);
5168

5269
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5370
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
54-
71+
// const category = document.querySelector('.mw-category');
72+
// const links = Array.from(category.querySelectorAll('a'));
73+
// const de = links
74+
// .map(link => link.textContent)
75+
// .filter(streetName => streetName.includes("de"));
76+
// console.log(de);
5577

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

5987
// 8. Reduce Exercise
6088
// Sum up the instances of each of these
61-
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
89+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck'];
90+
91+
const transportation = data.reduce((obj,item) => {
92+
if(!obj[item]){
93+
obj[item] = 0;
94+
}
95+
obj[item]++;
96+
return obj;
97+
},{});
98+
99+
console.log(transportation);
62100

63101
</script>
64102
</body>
65-
</html>
103+
104+
</html>

0 commit comments

Comments
 (0)