Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc0ea84

Browse files
Array Cardio Day 1
1 parent b63c531 commit bc0ea84

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

‎04_day/index.html

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>04 Day</title>
7+
</head>
8+
9+
<body>
10+
<p><em>Please have a look at the JavaScript Console</em> 💪</p>
11+
<script>
12+
const inventors = [{
13+
first: 'Albert',
14+
last: 'Einstein',
15+
year: 1879,
16+
passed: 1955
17+
},
18+
{
19+
first: 'Isaac',
20+
last: 'Newton',
21+
year: 1643,
22+
passed: 1727
23+
},
24+
{
25+
first: 'Galileo',
26+
last: 'Galilei',
27+
year: 1564,
28+
passed: 1642
29+
},
30+
{
31+
first: 'Marie',
32+
last: 'Curie',
33+
year: 1867,
34+
passed: 1934
35+
},
36+
{
37+
first: 'Johannes',
38+
last: 'Kepler',
39+
year: 1571,
40+
passed: 1630
41+
},
42+
{
43+
first: 'Nicolaus',
44+
last: 'Copernicus',
45+
year: 1473,
46+
passed: 1543
47+
},
48+
{
49+
first: 'Max',
50+
last: 'Planck',
51+
year: 1858,
52+
passed: 1947
53+
},
54+
];
55+
56+
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',
57+
'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',
58+
'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',
59+
'Blair, Tony', 'Blake, William'
60+
];
61+
62+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));
63+
64+
console.table(fifteen);
65+
66+
67+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
68+
console.log(fullNames);
69+
70+
71+
const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1);
72+
console.table(ordered);
73+
74+
const totalYears = inventors.reduce((total, inventor) => {
75+
return total + (inventor.passed - inventor.year);
76+
}, 0);
77+
78+
console.log(totalYears);
79+
80+
const oldest = inventors.sort(function(a, b) {
81+
const lastGuy = a.passed - a.year;
82+
const nextGuy = b.passed - b.year;
83+
return lastGuy > nextGuy ? -1 : 1;
84+
});
85+
console.table(oldest);
86+
87+
const alpha = people.sort((lastOne, nextOne) => {
88+
const [aLast, aFirst] = lastOne.split(', ');
89+
const [bLast, bFirst] = nextOne.split(', ');
90+
return aLast > bLast ? 1 : -1;
91+
});
92+
console.log(alpha);
93+
94+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck', 'pogostick'];
95+
96+
const transportation = data.reduce(function(obj, item) {
97+
if (!obj[item]) {
98+
obj[item] = 0;
99+
}
100+
obj[item]++;
101+
return obj;
102+
}, {});
103+
104+
console.log(transportation);
105+
</script>
106+
</body>
107+
108+
</html>

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ Thanks!
2828

2929
### Day 3: 20 Jun 2018
3030
Learned about CSS variables & updating them using JavaScript
31+
32+
### Day 4: 21 Jun 2018
33+
Learned more about JavaScript array methods like filter, map, sort, reduce & others.
34+
35+
![ES6 Arrow function](https://pbs.twimg.com/media/C0V10qtUcAAct4D.jpg)

‎index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<a class="active" href="./01_day/index.html">01 Day</a>
1313
<a class="active" href="./02_day/index.html">02 Day</a>
1414
<a class="active" href="./03_day/index.html">03 Day</a>
15+
<a class="active" href="./04_day/index.html">04 Day</a>
1516
</div>
1617
</body>
1718

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /