Visitar URL original
Add complete day 4 challenge · wesbos/JavaScript30@c4ddaa1 · GitHub
Skip to content

Commit c4ddaa1

Browse files
committed
Add complete day 4 challenge
1 parent a5c3f1b commit c4ddaa1

4 files changed

Lines changed: 73 additions & 155 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Array Cardio 💪</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="main.js"></script>
9+
</body>
10+
</html>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const inventors = [
2+
{ first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
3+
{ first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
4+
{ first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
5+
{ first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
6+
{ first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
7+
{ first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
8+
{ first: 'Max', last: 'Planck', year: 1858, passed: 1947 }
9+
]
10+
11+
const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William']
12+
13+
// 1. Filter the list of inventors for those who were born in the 1500's
14+
const filteredInventors = inventors.filter(inventor => {
15+
return inventor.year > 1499 && inventor.year < 1600
16+
})
17+
18+
// 2. Give us an array of the inventory first and last names
19+
const inventorNames = inventors.map(inventor => {
20+
return inventor.first + ' ' + inventor.last
21+
})
22+
23+
// 3. Sort the inventors by birthdate, oldest to youngest
24+
const sortedInventors = inventors.sort((a, b) => {
25+
return a.year > b.year ? 1 : -1
26+
})
27+
28+
// 4. How many years did all the inventors live?
29+
const totalYearsLived = inventors.reduce((total, currentInventor) => {
30+
return total + (currentInventor.passed - currentInventor.year)
31+
}, 0)
32+
33+
// 5. Sort the inventors by years lived
34+
const sortedYearsLived = inventors.sort((a, b) => {
35+
return (a.passed - a.year) > (b.passed - a.year) ? -1 : 1
36+
})
37+
38+
// 6. Create a list of Boulevards in Paris that contain 'de' anywhere in the name
39+
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
40+
// const catergory = document.querySelector('.mw-category')
41+
// const links = Array.from(category.querySelectorAll('a'))
42+
//
43+
// const containsDe = links.map(link => {
44+
// return link.textContent
45+
// }).filter(streetName => streetName.includes('de'))
46+
47+
// 7. Sort the people alphabetically by last name
48+
const alphabeticalLast = people.sort((prev, curr) => {
49+
const [prevLast, prevFirst] = prev.split(', ')
50+
const [currLast, currFirst] = curr.split(', ')
51+
return prevLast > currLast ? 1 : -1
52+
})
53+
54+
// 8. Sum up the instances of each of these
55+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck']
56+
const talliedData = data.reduce((obj, item) => {
57+
if (obj[item]) {
58+
obj[item]++
59+
} else {
60+
obj[item] = 1
61+
}
62+
return obj
63+
}, {})

‎04 - Array Cardio Day 1/index-FINISHED.html‎

Lines changed: 0 additions & 100 deletions
This file was deleted.

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)