Skip to content

Commit 9d0b8ab

Browse files
committed
day 4 and 5 done
1 parent b451bf5 commit 9d0b8ab

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,84 @@
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(inventor => inventor.year >= 1500 && inventor.year <= 1600)
41+
42+
43+
// console.table(fifteen)
4044

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

4450
// Array.prototype.sort()
4551
// 3. Sort the inventors by birthdate, oldest to youngest
52+
// const ordered = inventors.sort(function (a, b) {
53+
// if(a.year > b.year) {
54+
// return 1
55+
// } else {
56+
// return -1
57+
// }
58+
// })
59+
const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1)
60+
// console.table(ordered)
4661

4762
// Array.prototype.reduce()
4863
// 4. How many years did all the inventors live all together?
64+
// const totalYears = inventors.reduce(function (total, inventor) {
65+
// return total += (inventor.passed - inventor.year)
66+
// }, 0)
67+
68+
const totalYears = inventors.reduce((total, inventor) => {
69+
return total + (inventor.passed - inventor.year)
70+
}, 0)
71+
72+
// console.log(totalYears)
4973

5074
// 5. Sort the inventors by years lived
75+
const oldest = inventors.sort(function(a, b) {
76+
const lastGuy = a.passed - a.year;
77+
const nextGuy = b.passed -b.year
78+
return lastGuy > nextGuy ? -1 : 1
79+
// we are using the turniary above instead of the below if else
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'))
5492

93+
// const de = links
94+
// .map(link => link.textContent)
95+
// .filter(streetName => streetName.includes('de'))
5596

5697
// 7. sort Exercise
5798
// Sort the people alphabetically by last name
58-
99+
const alpha = people.sort((lastOne, nextOne) => {
100+
const [aLast, aFirst] = lastOne.split(', ')
101+
const [bLast, bFirst] = nextOne.split(', ')
102+
return aLast > bLast ? 1 : -1
103+
})
104+
// console.log(alpha)
59105
// 8. Reduce Exercise
60106
// Sum up the instances of each of these
61107
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
62108

109+
const transportation = data.reduce(function(obj, item) {
110+
if(!obj[item]) {
111+
obj[item] = 0
112+
}
113+
obj[item]++
114+
return obj
115+
}, {})
116+
console.log(transportation)
117+
63118
</script>
64119
</body>
65120
</html>

05 - Flex Panel Gallery/index-START.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
.panels {
2727
min-height: 100vh;
2828
overflow: hidden;
29+
display: flex;
2930
}
3031

3132
.panel {
@@ -43,6 +44,11 @@
4344
font-size: 20px;
4445
background-size: cover;
4546
background-position: center;
47+
flex: 1;
48+
justify-content: center;
49+
align-items: center;
50+
display: flex;
51+
flex-direction: column;
4652
}
4753

4854
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
@@ -56,7 +62,18 @@
5662
margin: 0;
5763
width: 100%;
5864
transition: transform 0.5s;
65+
border: 1px solid red;
66+
flex: 1 0 auto;
67+
display: flex;
68+
justify-content: center;
69+
align-items: center;
5970
}
71+
.panel > *:first-child { transform: translateY(-100%); }
72+
.panel.open-active > *:first-child { transform: translateY(0); }
73+
.panel > *:last-child { transform: translateY(100%); }
74+
.panel.open-active > *:last-child { transform: translateY(0); }
75+
76+
6077

6178
.panel p {
6279
text-transform: uppercase;
@@ -70,6 +87,7 @@
7087
}
7188

7289
.panel.open {
90+
flex: 5;
7391
font-size: 40px;
7492
}
7593

@@ -105,6 +123,22 @@
105123
</div>
106124

107125
<script>
126+
const panels = document.querySelectorAll('.panel')
127+
128+
function toggleOpen() {
129+
this.classList.toggle('open')
130+
}
131+
132+
function toggleActive(e) {
133+
134+
if(e.propertyName.includes('flex')) {
135+
this.classList.toggle('open-active')
136+
}
137+
138+
}
139+
140+
panels.forEach(panel => panel.addEventListener('click', toggleOpen))
141+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive))
108142

109143
</script>
110144

0 commit comments

Comments
 (0)